Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 57 ยท Describing Data

Mean, Median and Mode

Learn how to calculate and choose between the mean, median and mode, how outliers and skew affect them, and how to find each by hand and in Python.

When someone asks "what is typical?", you answer with a measure of central tendency: one number that stands for the center of a dataset. The three classic choices are the mean, the median and the mode. They often differ, and knowing why lets you pick the one that tells the truth instead of the one that sounds best.

The mean

The arithmetic mean (the average) adds all values and divides by how many there are:

mean = (x1 + x2 + ... + xn) / n

For the sample 4, 8, 6, 5, 7 the sum is 30 and n is 5, so the mean is 6. The mean uses every value, which makes it efficient but sensitive: one extreme value pulls it toward itself. A useful picture is a see-saw: the mean is the balance point of the data.

A handy property: the deviations from the mean always add to zero. For the sample above they are -2, 2, 0, -1, 1, and indeed they sum to 0.

The median

The median is the middle value after sorting. For an odd number of values it is the one in the center; for an even number it is the average of the two middle values.

  • 3, 5, 9, 12, 20 has median 9.
  • 3, 5, 9, 12 has median (5 + 9) / 2 = 7.

The median depends only on position, so extreme values barely affect it. We call this property robustness.

The mode

The mode is the most frequent value. A dataset can have one mode, several (bimodal, multimodal) or none when every value is unique. The mode is the only measure that works for nominal data such as favorite colors, and it is the one that actually exists in the data.

Python All three measures at once

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

How outliers change the story

Suppose six employees earn (in thousands) 40, 42, 45, 47, 48 and the owner earns 400. The mean is dragged far up by one value, while the median stays at the middle of the typical staff.

Python One outlier moves the mean, not the median

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The mean is about 103.7 with the owner and 44.4 without, a huge swing. The median moves only from 46 to 45. Reporting "the average salary is 103.7 thousand" would mislead.

Mean versus median and skew

The relationship between the two tells you about the shape of the distribution:

Shape Typical relation Example
Symmetric mean โ‰ˆ median Heights of adults
Right-skewed (long tail to the high side) mean > median Income, house prices
Left-skewed (long tail to the low side) mean < median Age at retirement for a profession
flowchart LR
    A["Symmetric<br/>mean = median = mode"] --> B["Right skew<br/>mode < median < mean"]
    A --> C["Left skew<br/>mean < median < mode"]

The mean is pulled furthest toward the tail, the median sits between, the mode stays at the peak.

The next lesson on skewness and kurtosis measures this precisely.

Which one should you use?

  • Mean: symmetric numeric data without strong outliers; needed for most later formulas (variance, regression).
  • Median: skewed data or outliers (income, house prices, response times).
  • Mode: categorical data, or when you want the most common value (most popular shoe size).

If the mean and median disagree noticeably, report both and say why.

Finding them from a frequency table

You will often get data as values and counts rather than a long list. With counts, the mean is sum(value * count) / sum(count). This idea grows into the weighted mean and grouped data.

Python Mean and median from counts

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Trimmed mean: a compromise

A trimmed mean discards a fixed share of the smallest and largest values (often 10% from each end) before averaging. It keeps most of the mean's efficiency while resisting outliers. Judges' scores in some sports use this idea.

Python A 20% trimmed mean with SciPy

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Common mistakes

  • Averaging percentages or rates without thinking about group sizes (see weighted means).
  • Calling the mean "the" average when another measure fits better.
  • Computing a mean of ordinal data like 1-to-5 ratings and treating differences as exact.
  • Forgetting to sort before taking the median by hand.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the median of 7, 1, 9, 3?

    Sorted: 1, 3, 7, 9. The middle two are 3 and 7, whose average is 5.
  2. 2. Incomes are strongly right-skewed. Which measure best describes a typical person?

    A few very high incomes pull the mean up; the median stays near the typical value.
  3. 3. Which measure can be used for favorite pizza topping?

    Nominal data has no order or arithmetic, so only the mode makes sense.
  4. 4. The data are 2, 4, 4, 6. What is the mean?

    The sum is 16 and n is 4, so the mean is 4.
  5. 5. In a right-skewed distribution, the usual order is...

    The long right tail pulls the mean up the most.

Summary

  • The mean is the balance point and uses every value; the median is the middle value; the mode is the most frequent.
  • Outliers move the mean a lot and the median little.
  • Mean greater than median hints at right skew, and the reverse at left skew.
  • Use the mode for categories, the median for skewed numbers, the mean for symmetric numbers.
  • A trimmed mean is a robust compromise.

Next: Weighted, Geometric and Harmonic Means