Each run starts with fresh data. Download any exported files before another run. Your written answers and code drafts are saved on this device; export your work to keep a backup.
M10C01 · Explore · predict · practice
Missing is not the same as empty or zero
isna() gives True where a value is missing. Zero is a recorded value, and an empty string is text unless you explicitly treat it as missing. Counting True values with .sum() counts missing entries.
Four values are now missing. The recorded zero is still zero.
Compare your explanations
Read. True/False values, one for each entry.
Predict. Three: None, pd.NA, and np.nan.
Explain. It is a stored text value. A cleaning rule must say whether blank text represents missing data.
One quick check
Which original value is known rather than missing?
What you should be able to explain. Define what missing means in your dataset.
M10C02 · Explore · predict · practice
Drop rows only for required fields
dropna(subset=[...]) removes rows missing the specified fields. It does not remove a row just because an unrelated field is missing. Keep a count of excluded records and consider how the exclusion affects the answer.
Ten rows remain out of thirteen. S004, S008, and S006 were excluded for the stated requirements.
Compare your explanations
Read. Score only.
Predict. Yes. S006 has a score, so it passes the Score-only requirement.
Explain. It may remove rows for fields the analysis does not need, changing the sample unnecessarily.
One quick check
What does subset specify?
What you should be able to explain. Match required fields to the analysis question.
M10C03 · Explore · predict · practice
Fill a label without inventing a measurement
fillna() replaces missing values with a value you specify. A label such as "Unknown" can make a missing category visible in a report. The same idea does not justify inventing a score or age.
Watch for this. Do not use zero as a universal replacement for missing numbers.
Your turn
Use the same Series, but first record a Boolean Was_missing flag. Store a DataFrame named result with the filled Campus column and the Was_missing flag.
For the code check, keep these result variable names: result. Different valid approaches are welcome.
The flag preserves which labels were originally missing, even after every cell contains text.
Compare your explanations
Read. A category label.
Predict. Two.
Explain. No. It makes the missing information explicit; it does not recover the campus.
One quick check
Why retain a missingness flag?
What you should be able to explain. Keep missingness visible when replacements are used.
M10C04 · Explore · predict · practice
Compare a fill policy with keeping missing data
Preview of Module 16: the groupby, transform, and named aggregation syntax in this cell will be explained there. First focus on the difference between a technical replacement and a justified data policy. A group median is one possible imputation rule, not a universal answer. transform() returns a group result for every original row. This small example compares a proposed fill with the original values so its effect is visible.
Program Hours Hours_filled Was_missing
0 AI 4.0 4.0 False
1 AI 8.0 8.0 False
2 AI NaN 6.0 True
3 IT 2.0 2.0 False
4 IT NaN 2.0 True
Watch for this. In predictive modeling, fit any imputation rule on training data only; do not learn it from held-out test data.
Your turn
Use the same original table. Keep the missing values and store a summary in result with Program as its index. Name the known Hours count Known_hours, the row count Rows, and the median Median_hours.
For the code check, keep these result variable names: df, result. Different valid approaches are welcome.
Show a hint
Use named aggregation; count counts known Hours, while size counts rows.