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






