Skip to main content
Albero Academy

Missing Data

Find, drop and fill NaN — where analyses are won or lost.

Cleaning & Transforming10 min

Real data has gaps. Pandas marks missing values as NaN (or NaT for dates, NA for newer types). Handling them deliberately — never ignoring them — is where analyses are won or lost, because missing values silently break sums and averages.

Finding missing values

always start here
df.isna().sum() # count NaNs per column
df.isna().mean() # fraction missing per column
df[df["email"].isna()] # rows where email is missing

Dropping vs filling

two strategies
df.dropna() # drop any row with a NaN
df.dropna(subset=["email"]) # only where email is missing
df["package"].fillna(0) # fill with a constant
df["package"].fillna(df["package"].median()) # fill with the median
df["package"].ffill() # carry forward the last value

Key takeaways

  1. 01Missing values are NaN/NaT — start with df.isna().sum() to quantify them.
  2. 02dropna removes rows/columns with missing values (use subset= to target).
  3. 03fillna fills with a constant, a statistic (median), or ffill/bfill.
  4. 04Choose deliberately: dropping can bias, filling invents — and document it.

Finished this chapter?

Mark it complete to track your progress through Pandas.