Statistics for Data Science · Day 3

Measures of Central Tendency

Finding the centre: mean, median, and mode, and when each one tells the truth.

By Shikhar · Series continued · ~13 min read

In Day 2, we learned how to sort data by type and scale. Now that we know what kind of data we have, the next question is simple: how do we sum it all up in one number? That's what today's article is about.

Why summarize data at all?

Imagine someone hands you a dataset with 10,000 customer purchases in it. You can't just stare at 10,000 numbers and understand what's going on. You need one number, a single value that tells you where most of the data sits. That's the "centre" of your data.

That's exactly what measures of central tendency do. The three most common ones are the mean, median, and mode. You might think one of them should be enough, but each one does a different job. By the end of this article, you'll know when to use which one, and why.

Note

Knowing the centre of your data is not the whole picture. You also need to know how spread out the data is. That's called dispersion, and it includes things like variance and standard deviation. We already touched on a few of these in Day 1 (standard deviation, IQR, MAD). Day 4 goes much deeper into them.

The mean (average)

The mean is what most people just call the "average." It's the most commonly used measure of central tendency, and you calculate it by adding up all the values and dividing by how many values there are. For a population, it's written as the Greek letter μ (mu). For a sample, it's written as x̄ (x-bar).

μ = x1 + x2 + ⋯ + xnn = ∑i=1n xin
where n is the number of values and xi is each individual value. μ (mu) is used for a population mean, x̄ (x-bar) for a sample mean.

Worked example

Let's look at the heights (in cm) of 7 people: [150, 155, 160, 160, 170, 175, 180]

μ = 150 + 155 + 160 + 160 + 170 + 175 + 1807 = 11507 ≈ 164.3 cm
pythonimport numpy as np data = [150, 155, 160, 160, 170, 175, 180] print(np.mean(data))
Output164.28571428571428

The outlier problem

The mean uses every single value in the dataset. That's good and bad at the same time. If you change even one value, the mean changes too. That's why one weird, far-off number, an outlier, can throw the mean way off.

Let's see what happens when we add an 8th value to the same dataset:

8th value addedNew mean
170 (a normal height)165.0
500 (an outlier)206.25

With the outlier of 500, the mean jumps to 206.25. But look at the actual data: nobody in it is anywhere close to 206.25 cm tall. That's the big problem with the mean, and it's exactly why we need the median.

Real-world example

This is why "average income" numbers can be so misleading. Picture a city where 999 people earn $40,000 a year, and one billionaire earns $1,000,000,000. The mean income there would be over $1 million a year! But the typical person in that city still earns $40,000. The median would show that clearly, while the mean hides it. It's the same lesson as Day 1's $200K salary example, just at the scale of a whole city.

The median

The median is the middle value once you sort your data from smallest to largest. It splits your data into two equal halves: half the values sit below it, half sit above it. The median only cares about position, which value is in the middle, not the actual size of the numbers. That's why outliers barely touch it.

How to calculate it

  1. Sort the data in ascending order (smallest to largest).
  2. If there's an odd number of values, the median is the middle value.
  3. If there's an even number of values, the median is the average of the two middle values.

Worked example

Our same 7 heights, sorted: [150, 155, 160, 160, 170, 175, 180]. The middle (4th) value is 160. That's the median.

Now add an 8th value of 170: [150, 155, 160, 160, 170, 170, 175, 180]. The two middle values are 160 and 170, so the median is (160 + 170) / 2 = 165.

Now add an outlier of 500 instead: [150, 155, 160, 160, 170, 175, 180, 500]. The two middle values are still 160 and 170, so the median is still 165.

The median didn't move at all when the outlier showed up. That property has a name: robustness.

pythonprint(np.median(data))
Output160.0
150 200 300 400 500 all 7 heights are packed in here the 500cm outlier Median = 165 Mean = 206.25
The mean gets pulled almost all the way toward the outlier. The median barely notices it moved.
When to use median over mean

Use the median whenever your data has outliers or is skewed (lopsided), like income, house prices, or how long people wait for something. The median gives you a much more honest picture of what's "typical."

The mode

The mode is simply the value that shows up the most in your data. Unlike the mean and median, the mode works on both numbers and categories (words). In fact, it's the only one of the three that works on categorical data, the same kind of data Day 2 told you never to average.

A dataset's mode can look like one of these:

Worked example (categorical)

A bank keeps a list of its customers' education levels: [Bachelor's, Master's, High School, Bachelor's, PhD, Master's, Bachelor's, Bachelor's].

The mode here is Bachelor's, since it shows up 4 times, more than anything else. This is the only one of the three measures that even makes sense on this list. You can't add up degree names to get a mean, and there's no way to sort them and find a "middle" degree either.

Worked example (numerical, bimodal)

[12, 15, 15, 18, 20, 20, 22, 25]

1 12 2 15 1 18 2 20 1 22 1 25
Frequency of each value in [12, 15, 15, 18, 20, 20, 22, 25]. Two values tie for tallest bar, which is what makes this bimodal.

Both 15 and 20 show up twice, more than any other number here. That makes this bimodal. When you see bimodal data, it's often a clue that you're actually looking at two different groups mixed together in one column, like two different age groups, or two different kinds of customers.

pythonfrom scipy import stats data_bimodal = [15, 15, 18, 20, 20, 22] print(stats.mode(data_bimodal)) # scipy breaks the 15-vs-20 tie by returning the smallest
OutputModeResult(mode=np.int64(15), count=np.int64(2))

One small heads-up if you run this yourself: newer versions of scipy and numpy print numbers a little differently. You'll see mode=np.int64(15) instead of the plain mode=15 that older tutorials show. Don't worry, it's still just the number 15. Only how it gets displayed changed, not what actually happened. It picked 15 because that's the smaller of the two tied values.

Going further: splitting the difference with a trimmed mean

Mean and median aren't your only two choices. There's a middle option called a trimmed mean. Here's how it works: sort the data, cut off a set percentage from each end, then take the mean of what's left. It's still a real mean, you just remove the most extreme values first.

pythonfrom scipy import stats heights_with_outlier = [150, 155, 160, 160, 170, 175, 180, 500] print("Mean: ", np.mean(heights_with_outlier)) print("Median: ", np.median(heights_with_outlier)) print("Trimmed mean:", stats.trim_mean(heights_with_outlier, 0.125))
OutputMean: 206.25 Median: 165.0 Trimmed mean: 166.66666666666666
150 200 300 400 500 trimmed these 6 get averaged trimmed Mean = 206.25 Median = 165 Trimmed mean = 166.7
Cut off the lowest and highest point, then average what's left. The trimmed mean lands almost exactly where the median is, while the untrimmed mean is still off to the right.

Cutting 12.5% off each end of 8 numbers means removing exactly 1 number from each side, so it drops the 150 and the 500. What's left gets averaged like normal. The result lands right next to the median. Either number tells you basically the same story here, but this one is still technically a mean, just a smarter one.

A lot of real scoring systems use this exact trick. Olympic judges trim the highest and lowest scores before averaging for exactly this reason. It keeps most of what makes a mean useful, while stopping one wild score from deciding the whole outcome.

Choosing the right measure

This next part might be the most useful part of the whole article. Picking the wrong measure can lead you straight to the wrong conclusion.

MeasureBest used whenAvoid when
MeanData is balanced, has no big outliers, and is interval or ratio scaleData is skewed or has outliers
MedianData is skewed, has outliers, or is ordinalYou need the result for other calculations that are built around the mean, like variance
ModeData is categorical, or you just want the most popular valueData is continuous with no repeated values, since then there may be no mode at all

A decision rule of thumb

  1. Is the data categorical? Use the mode.
  2. Does the data have big outliers, or is it skewed? Use the median.
  3. Neither of the above? Use the mean.

The effect of distribution shape

Where the mean, median, and mode land compared to each other can actually tell you something about the shape of your data.

Distribution shapeTypical relationshipWhat it means
Symmetric (normal)Mean = Median = ModeData is balanced around the centre
Right-skewed (positive skew)Mode < Median < MeanA few very large values are pulling the mean right
Left-skewed (negative skew)Mean < Median < ModeA few very small values are pulling the mean left
Symmetric Mean = Median = Mode balanced around the centre Right-skewed Mode Median Mean long tail pulls mean right Left-skewed Mode Median Mean long tail pulls mean left
The gap between mean and median is a quick tell for skew: the mean always gets dragged toward the longer tail.
Practical tip

If the mean and median in your dataset are far apart, that's a strong sign your data is skewed. Go look for outliers. This is one of the first things good data scientists check when they start exploring a new dataset, a step that even has its own name: exploratory data analysis, or EDA.

A common oversimplification

Here's something most textbooks don't tell you: the "typical relationship" column above is just a rule of thumb, not a rule that always works. It holds up well for smooth, single-peak distributions. But a researcher named Paul von Hippel showed in 2005 that it breaks more often than most people think, especially with whole-number data or data that has more than one peak. So treat this table as a helpful clue, not a promise. If your mean and median are far apart, skew is a good first guess, but it's still worth looking at the actual shape of your data before deciding anything for sure.

Real-world case study: e-commerce analytics

An online store looks at how much each order was worth (in USD) over one month. Most orders are between $20 and $80. But a few big company orders of $5,000 or more show up in the same list.

MetricValueInterpretation
Mean$312.00Pulled way up by the bulk orders, not representative
Median$47.00The typical customer spends $47, an accurate picture
Mode$29.00The single most common order value

If a junior analyst reported the mean ($312) as the "average order value," that could lead to some bad business decisions. A good data scientist always checks whether the mean and median are close to each other. If they're not, that gap is a warning sign that the mean is hiding something.

Key takeaway and a practical tip

The mean, median, and mode aren't rivals fighting for the same job. They're a team, and each one tells you something different. In any real project, calculate all three and compare them. The gaps between them tell you just as much as the numbers themselves do.

Quick reference:

Quick check

Three questions to test whether this stuck.

A dataset of 9 house prices has a mean of $450,000 and a median of $310,000. What does that gap tell you?

The data is probably right-skewed, most likely because one or a few expensive houses are pulling the mean upward. The median, $310,000, is the more honest number for describing a "typical" house in this set.

Why can't you compute a mean or median for a column of favorite pizza toppings?

Because topping names are nominal data: there's no number to add up, and no meaningful order to find the middle of. The mode, the most commonly picked topping, is the only measure of central tendency that applies here.

A dataset is perfectly symmetric but has two equally common peaks, like a class with one cluster of students who studied and one cluster who didn't. What happens to "mean = median = mode" here?

It breaks down. A bimodal dataset can still be symmetric, with mean and median landing in the same spot in the middle. But there's no single mode, since two values are tied for most common. This is exactly the kind of case the "common oversimplification" callout above was warning you about: a simple rule running into a shape it wasn't built for.

Up next in the series

Measures of Dispersion: range, variance, standard deviation, and IQR in depth. Because knowing the centre of your data is only half the story.