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.
M14C01 · Explore · predict · practice
Map codes to meaningful labels
Series.map() can look up each value in a dictionary. A code missing from the dictionary produces a missing result. Keep the source codes so you can investigate labels that were not mapped.
The CS row now has its specified label; the row without a source code remains missing.
Compare your explanations
Read. The codes we want to look up.
Predict. The entry for CS, which is not mapped, and the entry whose source code is missing.
Explain. One is an observed but unrecognized code; the other was never recorded.
One quick check
What happens to an unmapped key in Series.map with a plain dictionary?
What you should be able to explain. Check what a lookup leaves unmatched.
M14C02 · Explore · predict · practice
Apply a function to each value
A Python function can express a custom rule for one value. Series.apply() calls that function for each entry. When the same rule can be written with built-in column operations, those operations are often simpler and more efficient.
Read the example
scores = pd.Series([58, 79, 80, 95])
def status(score):
return "Secure" if score >= 80 else "Review"
result = scores.apply(status)
print(result.tolist())
Verified example output · pandas 2.2.3
['Review', 'Review', 'Secure', 'Secure']
Watch for this. These labels use an exercise rule, not an official grading policy.
Your turn
Create the same labels without a custom function. Use a Boolean comparison and a mapping from True/False to labels.
For the code check, keep these result variable names: result. Different valid approaches are welcome.
The labels are unchanged. The column comparison makes the threshold visible without a separate function.
Compare your explanations
Read. One score value, not the whole Series.
Predict. Secure, because the condition uses >=.
Explain. No. Built-in arithmetic, comparisons, string methods, and aggregations often do the job directly.
One quick check
What does ge(80) mean?
What you should be able to explain. Use a custom function when it adds clarity, not by default.
M14C03 · Explore · predict · practice
A row function versus column arithmetic
DataFrame.apply(..., axis=1) passes one row at a time to a function. Here Quiz is out of 20 and Project is out of 50, so both must be scaled before weighting them. A direct column formula can express the same calculation.
The percentages remain 80.0, 66.0, and 90.0. Direct arithmetic also preserves the row index.
Compare your explanations
Read. The function needs Quiz and Project from the same row.
Predict. 80.0: 16/20 contributes 32 and 40/50 contributes 48.
Explain. It would sum raw points without the stated 40% and 60% weights.
One quick check
With DataFrame.apply, axis=1 passes which object to the function?
What you should be able to explain. Prefer direct column formulas for ordinary arithmetic.
M14C04 · Explore · predict · practice
Fixed intervals versus quantile groups
cut() groups numbers using value boundaries that you choose. qcut() uses sample quantiles to form groups with roughly similar counts. They answer different questions, and equal-count groups need not have equal numeric widths.
Watch for this. Tied values can prevent qcut from making the requested number of distinct bins; inspect boundaries and group counts.
Your turn
Use students(). Create Score_band using boundaries 0, 60, 80, 100 with labels Developing, Progressing, Secure. Include both 0 and 100, with 60 in Developing and 80 in Progressing. Store the count of each band in a Series named result.
For the code check, keep these result variable names: result. Different valid approaches are welcome.
Show a hint
Use cut with right=True and include_lowest=True, then value_counts(sort=False).