Describing Data: Mean, Median & Mode
Lesson 1 of 5 · View course roadmap
Learn the idea
Before charts, before machine learning, analysis starts with three questions — and Python's built-in statistics module answers all of them:
mean(data)— the average. Honest for balanced data, easily dragged around by one extreme valuemedian(data)— the middle value. Robust: one billionaire in the room changes the mean salary wildly, the median barelymode(data)— the most common value. The only one that also works on words and categories
Knowing which to reach for is the analysis skill: report medians for incomes and house prices, means for balanced measurements, modes for "what's most popular?".
Where you'll use this
'Median household income', 'average response time', 'most common error' — every metrics dashboard and news statistic is these three functions. Choosing mean vs median honestly is half of data literacy.
Common mistakes
- Reporting the mean of skewed data (salaries, house prices, response times) — one outlier misleads everyone downstream.
- Calling mode() on data with no repeats — in older Pythons it raised; modern statistics.mode returns the first value, which may surprise you.
- Doing sum(x)/len(x) on an empty list → ZeroDivisionError. Guard empty datasets before describing them.
Pro tip
statistics.quantiles(data, n=4) gives quartiles — the p25/p50/p75 shape of your data. Engineers report p95 latency, not the average, for exactly the outlier reasons above.
Try it yourself
The lesson example is loaded and ready — press Run, then change something and run it again. Breaking it is part of learning. Want a clean slate? Tap “New blank”.
Output appears here…
Pass the challenge +30 XP
For scores = [72, 88, 95, 64, 88, 79] print three lines: the mean shown with 1 decimal place, the median, and the mode.
81.0 83.5 88
print(f"{statistics.mean(scores):.1f}") formats to one decimal place, then statistics.median(scores), then statistics.mode(scores).
import statistics
scores = [72, 88, 95, 64, 88, 79]
print(f"{statistics.mean(scores):.1f}")
print(statistics.median(scores))
print(statistics.mode(scores))
Run your code to check it…
Check your understanding
Your notes (saved on this device)
Tip: use ← and → to move between lessons, ⌘K to search everything.