Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Exploring and Plotting Data  ›  Lesson

Mean, Median and Mode

Mean, Median, Mode 12 minThe mean is the balance point, the median is the middle of the sorted values, and the mode is the most frequent value, and a gap between mean and median signals skew.

Mean, Median and Mode

"What is a typical sale?" sounds like one question with one answer. It is not. There are three common ways to describe the centre of a column, and on the same data they can disagree sharply. Knowing which one to quote is the start of honest analysis.

The rule

Mean balances, median splits, mode repeats.

Back to the clean sales table, with copies 3, 5, 2, 4, 1, 6, 2, 3.

  • Mean: add everything, divide by how many. The balance point. 26 / 8 = 3.25.
  • Median: sort and take the middle. With an even count, average the two middle values. Sorted: 1 2 2 3 3 4 5 6; the middle pair is 3 and 3, so the median is 3.0.
  • Mode: the most frequent value. Here 2 and 3 each appear twice, so there are two modes.
sales["copies"].mean()      # 3.25
sales["copies"].median()    # 3.0
sales["copies"].mode()      # 0    2
                            # 1    3

mode() returns a Series, not one number, precisely because ties happen. It also works on text: sales["genre"].mode() gives fiction and science, tied on three sales each.

Now the lesson that matters. A school orders 60 copies in one bulk sale. Add it, making nine values:

with_bulk = pd.concat([sales["copies"], pd.Series([60])])
with_bulk.mean()      # about 9.56
with_bulk.median()    # 3.0

One unusual sale nearly tripled the mean, while the median did not move. The mean feels every value's size; the median only cares about order.

Each of these works per group too: sales.groupby("branch")["copies"].median().

The shortcut

Before quoting a centre, compare mean and median. Close together: the data is roughly balanced, and the mean is fine. Far apart: something large or small is pulling the mean, so quote the median (and look at that value). Use the mode for categories, where there is nothing to add up.

Typical revenue per saleStep 1 of 4
  1. Compute both

    Revenue per sale is 750, 2000, 800, 1000, 250, 720, 240, 1200. The mean is 6960 / 8 = 870.

The trap is reporting the mean of skewed data, such as incomes or order sizes, as "typical". A few giants make the mean describe almost nobody.

Drills

Answer fast — trust the rule.

quick drill

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

quick drill

What is the median of price: 250, 400, 400, 250, 250, 120, 120, 400?

quick drill

Why does sales["copies"].mode() return two values?

quick drill

Salaries at a small firm: seven people earn around 30,000 and the owner earns 900,000. Which figure best describes a typical salary?

Remember

  • Mean balances, median splits, mode repeats.
  • Compare mean and median: a big gap means something is pulling the mean.
  • mode() returns a Series because ties are normal.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainWhat is a typical order?

An online shop's order values have a mean of 2,400 rupees and a median of 900. Explain what this gap tells you and which number you would quote as a typical order.