← Learning Hub
Data analysisFREE IN BOTH LANGUAGESLesson 06 / 12

Mean, median & grouped summaries

Use more than one number to understand what your data says.

Download notes (.md)

Downloads are text notes. Choose Save as PDF in your browser’s print dialog for a PDF copy.

Understand the concept

The mean adds values and divides by their count. The median is the middle value after sorting, or the average of the two central values for an even count. Large extremes can move the mean much more than the median.

A grouped summary reveals differences that an overall average can hide. Include sample sizes: a mean from two observations has a different evidential weight from a mean from two thousand. Missing values are excluded by many Pandas aggregations, so report them when relevant.

Descriptive patterns do not establish cause and effect. A relationship between study time and marks could also reflect prior preparation or other factors. Here, use a deliberately tiny sample to practise calculations rather than make claims about learners. The code uses only Python’s standard library.

Run the example

from statistics import mean, median
hours = [1, 2, 2, 3, 12]
print(f"Mean: {mean(hours):.1f}")
print(f"Median: {median(hours):.1f}")
print(f"Count: {len(hours)}")

Output / what to expect

Mean: 4.0
Median: 2.0
Count: 5

Try it yourself

Calculate the mean and median after removing 12. Explain what changed, without assuming the extreme value is an error.

View a suggested solution
from statistics import mean, median
hours = [1, 2, 2, 3]
print(mean(hours))    # 2
print(median(hours))  # 2.0
# The mean falls; the median stays the same.
# Investigate whether 12 is valid before deciding to exclude it.

Reference: Official documentation ↗

Make it yours.

Run the example and attempt the exercise before marking this lesson complete.

pass the idea on

What did this make you think?

You review and publish the post yourself. Instagram uses your device’s share menu when available; otherwise copy the text and link. Facebook opens the link composer, where you add your thoughts.