Skip to content
Start free

How do I read describe() for a column: mean versus median?

Read what describe() tells you: mean against median, quartiles, minimum and maximum, with four questions that work for any column.

Free course. Your Maestro, an AI, .

The histogram showed you the shape of trip duration. For a report, or to compare columns quickly, you also need numbers. pandas gives you all of them at once with describe(): how many values there are, the mean, the standard deviation, the minimum, the quartiles and the maximum.

The risk is reading a single number and believing it describes the column. The most tempting one is the mean. Before you see Rueda's summary, a small test with six made-up trips: five normal ones and one that someone forgot to end.

Write down what you think the program prints and why, before you run it.

Write down what you think the program prints and why, before you run it.

Five trips and a forgotten one

mediana.py
import pandas as pd

duraciones = pd.Series([12, 15, 18, 20, 22, 1450])
print("mediana:", duraciones.median())
print("promedio:", round(duraciones.mean(), 1))

A guess is fine: it's kept as you wrote it, so you can compare. Only you and your Maestro see your predictions.

Make your prediction

In Rueda the same thing happens on a different scale. The mean duration is 34.04 minutes and the median is 19.1. If you remove the three trips of more than 600 minutes, the mean drops to 20.5 and the median barely moves, to 19.05. Three trips out of 303 shift the mean by more than ten minutes.

That's why a wide gap between the mean and the median is a clue: something in one of the tails is pulling the mean. Here it's on the right, as you saw in the histogram. To say how long a typical Rueda trip lasts, the median is more honest; the mean is still useful for other things, like estimating total minutes of use, but not for describing one trip.

Two more numbers in the summary deserve a sentence. The quartiles split the sorted values into four parts with the same number of trips: the 25% says a quarter of the trips last less than 13.8 minutes, and the 75% says three quarters last less than 25.45. Between the two sits the middle half, the steadiest part of the column, because extremes don't move it. The standard deviation (std) measures how far values typically fall from the mean; since it's computed from the mean, extremes pull on it too. When it comes out larger than the mean in a column that can't be negative, like a duration, there's almost always a long tail.

Run the summary and read it yourself.

Run describe() on the duration and notice the two numbers that surprise you most. Then change the column to anionacimiento and look at its minimum and maximum. You're done when you have both summaries; below, you read them with four questions.

Run describe() on the duration and notice the two numbers that surprise you most. Then change the column to anio_nacimiento and look at its minimum and maximum. You're done when you have both summaries; below, you read them with four questions.

Run your code to see what it prints and the value of its last expression. Every run starts fresh.

Ready to run your code.

Run your code to see its output here.

Data: viajes-rueda, 311 rows

Enter saves a cell and Escape leaves it as it was. Leave a cell empty for a missing value.

The exercise's data, "viajes-rueda". Your edits run with your code.
RowRemove
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Page 1 of 16

Run it yourself

Four questions for any describe()

Worked example · 4 steps

This is the describe() of duracion_min: count 303, mean 34.04, std 135.80, min 0.3, 25% 13.8, 50% 19.1, 75% 25.45, max 1452.6. What does it tell you before you see any chart?

Work out the next step yourself, then open it to compare.

Those four questions work for any numeric column: how many values, how far apart the mean and median are, how far out the extremes sit and whether each number makes sense for what it measures.

Try it: distance

Now it's your turn with distancia_km. The code already has the summary. Complete the line that counts the 0 km trips, remove the # from the last two lines and answer the four questions. If something in the summary doesn't add up, ask your Maestro what to look at.

Run the distance summary. Complete the line that counts the 0 km trips (replace the ... with the number) and remove the from the last two lines.

Run the distance summary. Complete the line that counts the 0 km trips (replace the ... with the number) and remove the # from the last two lines.

Run your code to see what it prints and the value of its last expression. Every run starts fresh.

Ready to run your code.

Run your code to see its output here.

Data: viajes-rueda, 311 rows

Enter saves a cell and Escape leaves it as it was. Leave a cell empty for a missing value.

The exercise's data, "viajes-rueda". Your edits run with your code.
RowRemove
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Page 1 of 16

Run it yourself

Distance behaves differently: the mean (2.26 km) and the median (2.28 km) nearly match, and the maximum, 6.53 km, isn't far off. It's a column without strong extremes. The oddity is at the other end: 32 trips of exactly 0 km. The column description says it's the distance between stations, so a trip that leaves from and returns to the same station measures 0 even if the rider went across town. Write it down: a zero in this column doesn't always mean the bike didn't move.

The summary of anio_nacimiento has its own surprise. If you didn't spot it, look at the minimum again before answering the last question.

Check yourself: In the describe() of anio_nacimiento, the minimum is 1900 and the median is 1985. What do you do with that minimum?