Mean, Median, and Mode Explained
Mean, median, and mode are the three measures of central tendency, the "center" of a dataset. The mean is the sum of the values divided by how many there are, the median is the middle value once the data is sorted, and the mode is the value that appears most often. For 10, 20, 20, 30, 40, 50, 100, the mean is 38.57, the median is 30, and the mode is 20.
Quick answer: Mean = sum of the values ÷ number of values. Median = the middle value of the sorted data, or the average of the two middle values when the count is even. Mode = the most frequent value. Use the mean for symmetric data without outliers, the median for skewed data such as income or house prices, and the mode for categories or the most common response.
How do you calculate the mean?
Add up all the values and divide by how many there are. For 10, 20, 30, 40 and 100, the sum is 200 and there are 5 values, so the mean is 200 ÷ 5 = 40.
# Example dataset: [10, 20, 30, 40, 100]
# Mean calculation
mean = sum(values) / len(values)
mean = 200 / 5 = 40
# Python
import numpy as np
mean = np.mean([10, 20, 30, 40, 100]) # 40.0
- Best for: Normally distributed data without outliers
- Problem: Sensitive to extreme values (100 pulls the average up)
How do you find the median?
Sort the values and take the middle one; with an even number of values, average the two middle ones. For 10, 20, 30, 40, 100 the median is 30, and for 10, 20, 30, 40 it is (20 + 30) ÷ 2 = 25.
# Example dataset: [10, 20, 30, 40, 100]
# Sorted: [10, 20, 30, 40, 100]
# Middle value (position 3 of 5) = 30
# Python
median = np.median([10, 20, 30, 40, 100]) # 30.0
# For even number of values, take average of middle two
median = np.median([10, 20, 30, 40]) # 25.0 (average of 20 and 30)
- Best for: Skewed data or data with outliers
- Advantage: Not affected by extreme values
How do you find the mode?
Count how often each value appears and pick the most frequent: in 1, 2, 2, 3, 4, 2, 5 the value 2 appears three times, so the mode is 2. A dataset can have two modes (bimodal), several (multimodal), or no mode at all if every value appears only once.
# Example dataset: [1, 2, 2, 3, 4, 2, 5]
# Mode = 2 (appears 3 times)
# Python
from scipy import stats
mode = stats.mode([1, 2, 2, 3, 4, 2, 5])
print(mode.mode) # 2
# Can have multiple modes (bimodal, multimodal)
# Example: [1, 1, 2, 2, 3] has modes 1 and 2
- Best for: Categorical data or finding most common value
- Use case: "What's the most popular product?" or "Most common rating?"
When should you use the mean, median, or mode?
Use the mean for roughly symmetric data without outliers, the median when the data is skewed or has outliers, and the mode for categorical data or when you need the most common value.
| Scenario | Best Measure | Why |
|---|---|---|
| Income data | Median | Billionaires skew the mean |
| Test scores (normal) | Mean | Symmetrical distribution |
| House prices | Median | Mansions skew the mean |
| Survey ratings | Mode | Find most common response |
| Product sizes sold | Mode | What size is most popular? |
Real-World Example: Salaries
One extreme value is enough to pull the mean away from the typical value: in these nine salaries, a single $250,000 salary lifts the mean to $68,556, while the median stays at $48,000.
salaries = [35000, 40000, 42000, 45000, 48000, 50000, 52000, 55000, 250000]
# Mean (Average)
mean_salary = np.mean(salaries) # $68,556
# Misleading! CEO salary pulls average way up
# Median (Middle value)
median_salary = np.median(salaries) # $48,000
# Better representation of "typical" salary
# Mode (Most common)
# Not useful here - all values unique
What does it mean when the mean is higher than the median?
It usually means the data is right-skewed: a few large values pull the mean up while the median stays with the typical value, as in the salary example above. A mean below the median usually signals left skew, such as exam scores bunched near the maximum with a few very low scores, and a mean close to the median suggests a roughly symmetric distribution.
Comparing the two takes seconds and tells you which one to report. It is the first check in 5 descriptive statistics you should always check first.
All Three Together in Python
NumPy calculates the mean and median, and scipy.stats.mode returns the mode.
import numpy as np
from scipy import stats
data = [10, 20, 20, 30, 40, 50, 100]
mean = np.mean(data) # 38.57
median = np.median(data) # 30.0
mode = stats.mode(data).mode # 20
print(f"Mean: {mean:.2f}")
print(f"Median: {median:.2f}")
print(f"Mode: {mode}")
SQL Examples
In PostgreSQL, AVG gives the mean, PERCENTILE_CONT(0.5) WITHIN GROUP gives the exact median, and MODE() WITHIN GROUP gives the most frequent value. Syntax varies by database: SQL Server, for example, supports PERCENTILE_CONT only as a window function with OVER and has no MODE() aggregate.
-- PostgreSQL: mean, median, and mode in one query
SELECT
AVG(salary) as mean_salary,
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY salary) as median_salary,
MODE() WITHIN GROUP (ORDER BY department) as mode_department
FROM employees;
Excel Formulas
Excel has a function for each measure: AVERAGE for the mean, MEDIAN for the median, and MODE.SNGL (or the older MODE) for a single mode, plus MODE.MULT to return every mode when there is a tie.
=AVERAGE(A1:A100) -- Mean
=MEDIAN(A1:A100) -- Median
=MODE.SNGL(A1:A100) -- Mode (#N/A if no value repeats)
=MODE.MULT(A1:A100) -- All modes (spills in Excel 365 and 2021)
What are common mistakes with mean, median, and mode?
The most common mistake is reporting only the mean for skewed data such as income, order values or response times, where it can sit well above what a typical value looks like. Report the median, or both.
- Averaging averages: if group A has 2 orders averaging $10 and group B has 8 orders averaging $50, the mean of the two averages is $30, but the true average order is (2 × 10 + 8 × 50) ÷ 10 = $42. Weight by count or calculate from the raw rows.
- Missing tied modes:
scipy.stats.modereturns only the smallest mode when values tie. Use pandas'Series.mode()to get all of them. - Filling gaps with the mean by default: for skewed columns the median is usually the safer fill value. See imputation methods for the trade-offs.
from scipy import stats
import pandas as pd
print(stats.mode([1, 1, 2, 2, 3]).mode) # 1 (smallest mode only)
print(pd.Series([1, 1, 2, 2, 3]).mode().tolist()) # [1, 2]
Key Takeaways:
- Mean: Best for symmetric data, but sensitive to outliers
- Median: Best for skewed data, resistant to outliers
- Mode: Best for categorical data or finding most common value
- Report all three: They tell different stories about your data