liveBook · Manning

Median

As explained in Grokking Statistics

The middle value of an ordered set of observations, or the midpoint of the two middle values when the set has even size.

The median is the middle value in an ordered list. It describes a typical value without letting an unusually large or small observation pull the result as strongly as the mean. section 2.12 section 2.14

Find the median by following two simple cases:

  • For an odd number of observations, select the single value in the center. In 1, 3, 5, 9, 11, the median is 5. section 2.14
  • For an even number, average the two center values. In 1, 3, 5, 8, 9, 11, average 5 and 8 to get 6.5. section 2.14

The high-roller problem

Nine bar tabs are [7, 18, 19, 20, 21, 22, 25, 120, 1500]. Python calculates a mean of $194.67 but a median of $21. The $1,500 tab is an outlier, so $21 better represents the typical patron’s bill. section 2.14

import numpy as np

bar_tabs = [7, 18, 19, 20, 21, 22, 25, 120, 1500]

mean = np.mean(bar_tabs)
median = np.median(bar_tabs)

print("Mean: ", mean)     # Mean:  194.666
print("Median: ", median) # Median:  21.0

Run the NumPy example to compare mean and median on the same list of bar tabs. section 2.14

A large difference between the mean and median can signal skew caused by extreme observations. Median is therefore especially useful for income and other economic data, though any dataset still needs context because samples can contain gaps and bias. section 2.14 section 2.21

How Grokking Statistics covers it

How deep it goes
Defines ordered selection and even-size averaging, then demonstrates outlier resistance with a worked calculation.
Examples
Uses ordered number lists and bar tabs containing a $1,500 outlier to compare median with mean.
What it assumes
Assumes no prior statistics, while teaching ordered numerical data and the distinction between samples and populations.
What you can do after
Apply it via NumPy and interpret whether the median better represents a typical observation than the mean.
How it connects
Contrasts median with mean and connects it to outliers, skew, descriptive statistics, samples, and economic data.

Also explained in

Compare how 7 books explain median →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Statistics. The section links point to the parts of the book it draws on.