Lesson 1 of 5 · 8 min · Centre and spread
Mean, median and mode: choosing the right average
What you will learn
- Calculate and explain the mean, median and mode
- Choose the right "average" for the question and the data
- See how outliers and skew separate the mean from the median
- Calculate a weighted average
- Compute each in Excel, SQL and Python
In simple words
When someone says "the average", they could mean three different things. The mean is what you get when you share the total equally. The median is the middle value when you line everyone up. The mode is the most common value. If one very large number sneaks into the list, the mean jumps but the median hardly moves, and picking the wrong one can make a report mislead.
Words to know
- Mean: the sum of all values divided by how many there are.
- Median: the middle value of a sorted list.
- Mode: the value that appears most often.
- Skew: when data has a long tail on one side, pulling the mean that way.
A worked example
Delivery times in days for nine orders:
2, 3, 3, 3, 4, 4, 5, 6, 15
- Mean: the total is 45, divided by 9 gives 5.0.
- Median: sorted, the middle (5th) of nine values is 4.
- Mode: 3 appears three times, the most, so the mode is 3.
Three different answers from the same data, and all three are correct. Which would you tell a customer? The mean (5 days) is pulled up by the one 15-day delivery. The median (4 days) says "half of orders arrive in 4 days or less". The mode (3 days) is the most common experience. For skewed data like delivery times, salaries and order values, the median is usually the honest "typical" figure, and many reports show the mean and median together.
Mean
mean = (x1 + x2 + ... + xn) / n
Strengths: uses every value, and is easy to combine (the mean of the whole is made from totals and counts). Weakness: sensitive to outliers. Remove the 15 and the mean of the other eight drops from 5.0 to 3.75.
Another example. Monthly salaries in thousands of rupees: 22, 25, 27, 28, 30, 31, 33, 35 and 90. The mean is 35.67 but the median is 30. The one 90 lifts the average above what eight of the nine people earn. When a company says "average salary is 35,670", ask for the median.
Median
Sort the values. With an odd count, take the middle one; with an even count, average the two middle ones. Strengths: robust, unaffected by extreme values. Weakness: ignores how large the extremes are, and cannot be built from sub-group medians.
Mode
The most frequent value. It is the only average that works for categories: the most common city, product or payment method. A dataset can have no mode (all different), one mode, or several (bimodal). For continuous numbers such as exact heights it is rarely useful unless you group the values into bins.
Which should you use?
| Situation | Best choice |
|---|---|
| Symmetrical data without outliers (exam marks in a big class) | mean |
| Skewed or outlier-prone (salaries, house prices, delivery times, order values) | median, shown with the mean |
| Categories (most popular product) | mode |
| Totals matter (revenue per customer to plan total revenue) | mean |
| Ratings 1 to 5 | mean and the full distribution (a mean of 3 can hide two camps of 1s and 5s) |
If mean and median are far apart, the data is skewed. That gap itself is a finding worth reporting.
Weighted average
When some values count more than others, weight them. Two branches: Hyderabad has 100 orders with a mean value of 800 and Pune has 20 orders with a mean of 1,400. The overall mean is not (800 + 1400) / 2 = 1100. It is:
(100 x 800 + 20 x 1400) / (100 + 20) = (80000 + 28000) / 120 = 900
Never average averages without weights. The same applies to averaging percentages of different-sized groups: add the numerators and denominators instead.
Calculating them
Excel:
=AVERAGE(A2:A10) =MEDIAN(A2:A10) =MODE.SNGL(A2:A10) =SUMPRODUCT(B2:B3, C2:C3)/SUM(B2:B3)
SQL (PostgreSQL):
SELECT AVG(days) AS mean,
PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY days) AS median,
MODE() WITHIN GROUP (ORDER BY days) AS mode
FROM deliveries;
MySQL has AVG but no built-in median or mode; compute the median with window functions (ROW_NUMBER and COUNT) or in Python.
Python:
import statistics as st
days = [2, 3, 3, 3, 4, 4, 5, 6, 15]
st.mean(days) # 5
st.median(days) # 4
st.mode(days) # 3
st.multimode([1, 1, 2, 2]) # [1, 2]
With pandas: df["days"].mean(), .median(), .mode() (returns a Series because there can be ties).
Common mistakes
- Reporting only the mean for skewed data.
- Averaging averages of groups of different sizes.
- Treating the mode as meaningful for unique, continuous values.
- Dropping missing values silently (the mean of the known values is not the mean of everyone).
- Mixing units (rupees and thousands) when averaging.
Try it yourself
- Calculate the mean, median and mode of the delivery times above by hand, then check with Python.
- Add an order that took 60 days and see which of the three moves.
- Compute the overall average order value of two branches with different order counts using a weighted average.
- Find the mean and median salary from a dataset you have; if they differ a lot, write one sentence on why.
Check yourself
When is the median better than the mean?
When the data is skewed or contains outliers, such as salaries or delivery times, because the median is not pulled by extreme values.
What is the mode used for?
The most common value; it is the only average that works for categories.
Why is the average of two groups' averages usually wrong?
It ignores how many values each group has. Use a weighted average, or recompute from totals and counts.
What does a big gap between mean and median tell you?
The distribution is skewed, with a long tail or outliers on one side.
Interview questions
The average salary in a company rose after the CEO's pay rise but nobody else's changed. Which statistic shows what happened?
The mean rose, because it uses every value, while the median did not change. The median better shows the typical employee.
How do you calculate the median in SQL?
In PostgreSQL, PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY col). In MySQL, number the rows with window functions and take the middle one or the average of the two middle ones.
Two cities have mean order values of 800 and 1,400 with 100 and 20 orders. What is the combined mean?
The weighted mean: (100 x 800 + 20 x 1400) / 120 = 900.
Summary
- Mean is the shared total, median is the middle, mode is the most common.
- Outliers move the mean but barely move the median; report both for skewed data.
- Use weighted averages for groups of different sizes.
- Excel, SQL and Python all have functions for each.
Going deeper
- statistics module: averages and measures of central tendency:
mean,median,modeand more. - PostgreSQL ordered-set aggregates:
percentile_contandmode. - pandas descriptive statistics:
mean,median,modeon DataFrames.
See how much of this you can explain
A free mock interview asks you new questions on Statistics for analysts for Data Analyst and scores every answer, with what to fix.