Topics / 🗄️ SQL, pandas & Data Analysis / 🧹 Level 18: Data Cleaning & Statistics

Python exercise · about 5 minutes · free

Missing Values

Blank incomes break averages and models. Count them, then decide what to do. Never ignore them silently.

s.isna().sum() counts missing values. s.fillna(value) fills them; the median is a common, outlier-resistant choice. Always record how many you filled.

Table. before: name, income; Kai | 45000; Mia | NaN; Zed | 52000; Ali | NaN; Nova | 38000. Operation: fillna(median = 45000). Result after: name, income; Kai | 45000; Mia | 45000; Zed | 52000; Ali | 45000; Nova | 38000. missing = 2 (always report how many you filled)beforenameincomeKai45000MiaNaNZed52000AliNaNNova38000afternameincomeKai45000Mia45000Zed52000Ali45000Nova38000fillna(median = 45000)missing = 2 (always report how many you filled)
Your quest: Set missing to the number of missing incomes, then fill them with the median of the known incomes.
Try it now Runs in your browser. No sign-in needed. Ctrl+Enter to run.
Hintmissing = df["income"].isna().sum(); df["income"] = df["income"].fillna(df["income"].median())
Output appears here.

Open it in the full course → Free with Google: saves your progress and unlocks 627 lessons.

In this level you'll learn:
More in Level 18: Data Cleaning & Statistics

Share on LinkedIn