Skip to content

Instantly share code, notes, and snippets.

@mmmayo13
Last active January 14, 2024 16:48
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save mmmayo13/7a81c3105001e503dbcb38ff23b74f9e to your computer and use it in GitHub Desktop.
Save mmmayo13/7a81c3105001e503dbcb38ff23b74f9e to your computer and use it in GitHub Desktop.
# Drop the columns where all elements are missing values:
df.dropna(axis=1, how='all')
# Drop the columns where any of the elements are missing values
df.dropna(axis=1, how='any')
# Keep only the rows which contain 2 missing values maximum
df.dropna(thresh=2)
# Drop the columns where any of the elements are missing values
df.dropna(axis=1, how='any')
# Fill all missing values with the mean of the particular column
df.fillna(df.mean())
# Fill any missing value in column 'A' with the column median
df['A'].fillna(df['A'].median())
# Fill any missing value in column 'Depeche' with the column mode
df['Depeche'].fillna(df['Depeche'].mode())
@navneethc
Copy link

The second and fourth examples are the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment