Session 6 Exercise — Aggregations and Summary Statistics
Optional enrichment — complete during the session if time allows, or finish independently on your fork.
Your Task
- Load
exercises/data/merged_contacts.csv(produced in the Session 5 exercise) - Use
pd.cut()on theenrollmentcolumn to create aschool_sizecolumn- Bins:
[0, 300, 700, inf]Labels:['Small (<300)', 'Medium (300-700)', 'Large (700+)']
- Bins:
- Print
value_counts()oncity_location— how many contacts attended schools in each city? - Use
groupby('school_size', observed=True)and.agg()to compute student count and average enrollment per size bucket - Save the size summary to
exercises/data/size_summary.csv(no index)
Starter Script
Open session_06_exercise.py and fill in the blanks marked with # TODO:. If you get stuck, the completed version is at session_06_answer.py.
Run from the repo root:
python exercises/session_06_exercise.py