Measures of Center
Mean vs median — the most important choice in descriptive statistics, and when each one misleads.
Your manager asks: 'What's the typical salary at our company?' You compute the mean: $120,000. But the CEO earns $5M. The median salary is $68,000.
Which number actually represents a typical employee? The median does — the mean is being dragged upward by one extreme value. This is the most consequential choice in descriptive statistics.
import pandas as pd
import numpy as np
salaries = pd.Series([55000, 62000, 68000, 70000, 75000, 80000, 5000000])
print(f'Mean: ${salaries.mean():,.0f}') # $773,000
print(f'Median: ${salaries.median():,.0f}') # $70,000
# Rule of thumb: if mean ≠ median significantly, check for skew
print(f'Skew: {salaries.skew():.1f}') # high positive = right-skewed- Use median for: salaries, prices, house values, any dollar amount with outliers
- Use mean for: symmetric data, test scores, temperatures, things without extreme outliers
What does this print?
import pandas as pd
data = pd.Series([10, 20, 30, 40, 200])
print(data.mean())
print(data.median())- A60.0 30.0
- B30.0 30.0
- C60.0 40.0
- D200.0 30.0
# Step 1: compute both
print(df['price'].describe())
# Step 2: compare mean vs median
mean = df['price'].mean()
median = df['price'].median()
ratio = mean / median
if ratio > 1.2:
print('Right-skewed — report median')
elif ratio < 0.8:
print('Left-skewed — report median')
else:
print('Roughly symmetric — mean is fine')If mean/median > 1.2 (mean is 20%+ above median), the data is right-skewed. Use median in any report.
A real estate report says 'average home price: $450,000'. The median is $280,000. Why might 'median' be the more honest number to report?
- AMedian is always more accurate than mean
- BA few very expensive homes pull the mean far above what most buyers would actually pay
- CReal estate statistics always use median by convention
- DThe average includes commercial properties
col = df['order_value']
print(f'Mean: {col.mean():.2f}')
print(f'Median: {col.median():.2f}')
print(f'Skew: {col.skew():.2f}')
# Visualize
col.hist(bins=50)These three lines tell you: what's the center, is it being distorted by outliers, and what shape is the distribution. You know in 30 seconds whether to trust the mean.
Get the median of the 'revenue' column:
median_rev = df['revenue'].___()df['duration'].skew() returns 3.8. What does this mean and which measure should you report?
- AThe data is normally distributed — use the mean
- BThe data is heavily right-skewed (long tail of high values) — report the median to avoid inflating the 'typical' duration
- CThe skew value is too high — there must be a calculation error
- DThe data is left-skewed — use the mean since it underestimates the typical value