Examples
import numpy as np
import pandas as pd
df = pd.DataFrame({"name": ['Superman', 'Batman', 'Spiderman'],
"toy": [np.nan, 'Batmobile', 'Spiderman toy'],
"born": [pd.NaT, pd.Timestamp("1956-06-26"),
pd.NaT]})
df
Drop the rows where at least one element is missing:
df.dropna()
Drop the columns where at least one element is missing:
df.dropna(axis='columns')
Drop the rows where all elements are missing.
df.dropna(how='all')
Keep only the rows with at least 2 non-NA values:
df.dropna(thresh=2)
Define in which columns to look for missing values:
df.dropna(subset=['name', 'born'])
Keep the DataFrame with valid entries in the same variable:
df.dropna(inplace=True)
df