Skip to content

Instantly share code, notes, and snippets.

@asif31iqbal
Last active July 26, 2017 20:28
Show Gist options
  • Save asif31iqbal/c227226b432f57c96091469c8680028b to your computer and use it in GitHub Desktop.
Save asif31iqbal/c227226b432f57c96091469c8680028b to your computer and use it in GitHub Desktop.
pandas cheatsheet
import pandas as pd
df = pd.DataFrame({'id': [12, None, 56], 'name': ['asif', 'iqbal', 'anika']})
# df to numpy array
df.values
# df to boolean df (null/ notnull)
df.notnull()
# oppposite of notnull
df.isnull()
# select rows with all not-null values
df[df.notnull().all(axis=1)]
# select rows with any not-null values
df[df.notnull().any(axis=1)]
# select rows with all null values
df[df.isnull().all(axis=1)]
# select rows with any null values
df[df.isnull().any(axis=1)]
# select columns with any null values
df.isnull().any()
df.columns[df.isnull().any()].tolist()
# select columns with all null values
df.isnull().all()
df.columns[df.isnull().all()].tolist()
# select columns with any not null values
df.notnull().any()
df.columns[df.notnull().any()].tolist()
# select columns with all not null values
df.notnull().all()
df.columns[df.notnull().any()].tolist()
# whether all values of all columns are not null
df.notnull().values.all()
# whether all values of all columns are null
df.isnull().values.all()
# whether any value of any columns is not null
df.notnull().values.any()
# whether any value of any columns is null
df.isnull().values.any()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment