Pandas Cheat Sheet

Feb. 13, 2022, 2:45 p.m.

Creating a new column based on conditions of another or other columns using np.where():

df['new_column'] = np.where(df['existing_column'] > value, True, False)

Setting options in Pandas so that you can see more rows, columns or column width that in the default:

import pandas as pd
pd.set_option('display.max_rows', 500)
pd.set_option('display.max_columns', 500)
pd.set_option('display.width', 1000)

Identifying the delta between two lists in python from W3Schools:

x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.difference(y)
print(z)

Identifying the intersection between two lists in python from W3Schools:

x = {"apple", "banana", "cherry"}
y = {"google", "microsoft", "apple"}
z = x.intersection(y)
print(z)

~No Further Entries~

 

 


Comment Count: 0 Comments: