Skip to content

Pandas Operations

NaN Operations

Drop Rows with all Null Values

df.dropna(how = "all", inplace = True)

Drop Specific Rows where Columns have Null Values

df.dropna(subset = ['column1', 'column2']

Fill Null with Defalt Values per Column

df['column'].fillna(0, inplace=True)

Type Operations

Change Column Type to INT

df['column'] = df['column'].astype("int")

Change Column Type to Category ( Saves Mem on Big Data Sets )

df['column'] = df['column'].astpe("category")

Sort Operations

Sort by Single Column

df.sort_values("column1", ascending = False)

Sort by Multiple Columns

df.sort_values(["Team", "Name"], ascending = [True, False], inplace = True)

Sort by Index

df.sort_index(ascending = False, inplace = True)

Add Rank to Column

df["Salary Rank"] = df["Salary"].rank(ascending = False).astype("int")
Back to top