Lesson 6 of 12 · 30 min · Grades 9–12
Working with a table of numbers
The sports teacher keeps 100 m times in a register. You load them as a list, then compute fastest, slowest and average — the start of data work. pandas will later do this on 50,000 rows; the idea is the same: a column of numbers, then aggregations.
Sports register
min, max and mean from a table.
You will be able to
- ✓ Use min, max, sum, len
- ✓ Compute a simple average
Built-in aggregations
min and max scan a list. sum adds. Divide by len for the mean. Watch empty lists in real apps — dividing by zero is a crash, not a philosophy.
Name the list after the quantity: times, scores, temps. Then print("Fastest", min(times)) reads like a report heading.
A column is not a story until you summarise it
Raw times are for the coach who wants every athlete. The noticeboard wants three numbers: fastest, slowest, average. That split — keep the raw list, publish the summary — is how dashboards work. pandas will later call this describe(); you are doing it by hand.
Units belong in the label. Average 14 means nothing if one house recorded seconds and another recorded minutes. Write print("Average seconds", ...).
Empty and dirty lists
If nobody ran, times is []. Mean is undefined. Real programs check len(times) > 0 before dividing. A stray 0 that meant “did not start” will pull the average down — that is a data-cleaning problem you will meet again in Advanced pipelines.
sorted(times) gives a rank list without destroying the original. Keep arrival order if you still need “who ran first”.
Words that matter
- Aggregation
- A summary of many values: min, max, mean, count.
Common mistakes
Avoid: Average as max - min.
Do this: Mean is sum / len.
Example program — House race times (seconds)
Lower is faster.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Your turn — Test scores
scores = [70, 80, 90]. Print the average 80.
Edit the example, press Run, then Build if you want a compile check.
build
Press Build to compile.
Self-assessment
Check your understanding before you mark the lesson complete.
Progress is stored in a browser cookie on this device.