Good place to stop if you're short on time — step 3 picks up here.
Lesson idea Tap to fold
Why can a missing label be more serious than a missing note?
Show the answer
The label may be required for the analysis; a note may be optional.
Missingness is evidence, not automatically zero
pandas represents missing data with sentinels such as None, NaN or pd.NA, depending on dtype. isna detects missing values; comparing directly with a sentinel is not a reliable test. Empty strings and zero are present values, not missing by default.
isna().sum() counts missing values by column. fillna replaces missing entries with an explicit default; this course permits no note for optional notes, not a fabricated numeric score. Assign the filled notes Series back to its column. dropna(subset=[...]) rejects rows missing only the named required fields. After counting, to_dict converts the resulting Series into an ordinary dictionary of column-name keys and count values. It changes the representation, not the missing-data policy.
An absent required column is a schema problem, not an ordinary missing cell. A row with a missing optional note may still be usable. These demonstrations test missingness only, not whether a present ID or label is valid.
# Missingness is evidence, not automatically zero.
import pandas as pd
df = pd.DataFrame([
{"item_id": "Museum", "notes": None},
{"item_id": "Canal", "notes": ""},
])
print(df["notes"].isna().tolist())
df["notes"] = df["notes"].fillna("no note")
print(df["notes"].tolist())
[True, False], then ['no note', '']. The present empty note stays empty, rather than being replaced by the fallback.
State the policy before filling or dropping data, and retain exclusion counts when building an audit.
Predict, explain, then test
These three brief checks are self-reviewed, not scored. Answer before opening the comparison. Coding checks use unfamiliar tables under the stated task assumptions.
Distinguish values
Are None, empty string and zero all missing?
Compare your answer · self-reviewed
No. None is missing; empty text and zero are present by default.
Bound a drop
Why name a subset when dropping rows?
Compare your answer · self-reviewed
Only those required fields determine rejection; missing optional notes should not remove a row.
Defend a default
Why not fill missing evaluation scores with zero before calculating a mean?
Compare your answer · self-reviewed
Zero invents an observation and changes the denominator/mean. Report missingness and the number of scored rows.
Choose an exercise to load its prompt.
Loading exercises…
Noted on your route map, with the step you were on. Nothing is lost by parking it — the next review day will bring this idea back, and the flag tells the course where to slow down.
The tutor mounts here when JavaScript is available. The lesson above stays readable without it.