Data Science · Level 3 Cleaning

Missing Data in pandas

Find the gaps in a customer table, drop the rows that have no email and fill missing ages with the median.

  • isna().sum() counts the gaps
  • dropna(subset=[...])
  • fillna() returns new data

df.isna().sum() counts missing values per column. dropna(subset=[...]) removes incomplete rows and fillna(value) fills the gaps. Trap: both return new data, so assign the result back.

df["age"].fillna(df["age"].median())              # df unchanged!
df["age"] = df["age"].fillna(df["age"].median())  # saved

Write clean_customers(df) that drops the rows with no email, then fills missing age values with the median age of the rows that are left, for example remaining ages [30, None, 40] become [30.0, 35.0, 40.0].

solution.py
Test Suites Pending
Output