DATA SCIENCE · CYCLE 2 · L17 · TEXTBOOK CHAPTER
Catch the Ruler
In class, pairs caught a falling ruler and asked what a typical catch is. There are two ways to say what is typical: the mean and the median. One value far from the rest pulls the mean a lot and barely moves the median.
After this chapter, you can
- Find a mean and a median by hand.
- Say what one outlier does to each.
- Choose the center that describes a typical value.
- Run
=AVERAGE, =MEDIAN and a histogram in Sheets.
For your project: the mean and the median of your number go on ANALYSIS. The checkpoint is at the end.
Why It Matters
One very large house moves the street’s mean. It barely moves the median.
The Census Bureau reports a typical US household’s income for 2023 as $80,610. That is a median.
The same report gives the mean: $114,500. The mean is $33,890 higher than the median. So why does the report give the median first? Six made-up households show why.
| Five households | Add one very rich household |
| Incomes | $40,000, $60,000, $80,000, $100,000, $120,000 | the five and $10,000,000 |
| Mean | $80,000 | $1,733,333 |
| Median | $80,000 | $90,000 |
One household moved the mean by more than $1.6 million. It moved the median by $10,000. A typical household is the middle one, so the report gives the median first.
The real numbers work the same way. The households with the largest incomes pull the mean up to $114,500. The middle household is at $80,610.
The Idea
Two ways to say what is typical
The mean is the total shared out evenly. The median is the middle value once they are in order. Each one is a center: one number for what is typical. With an even count, the median is the mean of the two middle values.
| Center | How to find it | An outlier |
| mean | add them all, divide by how many | pulls it a lot |
| median | put them in order, take the middle | barely moves it |
When a few values sit far out, the median describes a typical one.
An outlier is a value far from the rest. The mean uses the size of every value, so one outlier pulls it. The median uses only the order. An outlier just becomes the biggest value, and the middle barely moves.
Sheets calls the mean AVERAGE. When people say “the average”, they mean the mean.
The Shape Tells You Which Is Bigger
A histogram is bars that count how many values fall in each range. This one shows the weights in the class file from L17.
Weight of 12,579 students, CDC Youth Risk Behavior Survey. Each bar is 5 kg wide. The solid line is the median and the dashed line is the mean. 11 students outside 30 to 150 kg are left off.
Most students are in the bars from 45 to 80 kg. A thin run of bars stretches right, as far as 150. That is a long tail of big values, so the data are skewed right.
The few students who weigh much more pull the mean toward the tail. The median is the middle student and barely moves. So the mean, 67.9 kg, sits above the median, 64.4 kg.
Worked Examples
Example 1 · The mean and the median by hand. Mia sent 23, 8, 31, 14 and 9 texts on five school days. Find the mean and the median.
Create a strategyMean: add them all, then divide by how many. Median: put them in order first, then take the middle.
Apply the idea
Mean: 23 + 8 + 31 + 14 + 9 = 85, and 85 ÷ 5 = 17. Mean = 17 texts.
In order: 8, 9, 14, 23, 31. There are five values, so the middle is the third. Median = 14 texts.
Reflect and checkThe middle of the list as Mia wrote it is 31, the biggest value. That is why you put the values in order first. Check it in Sheets: type the five values in A1 to A5, then =AVERAGE(A1:A5) in C1 and =MEDIAN(A1:A5) in C2. They show 17 and 14.
Example 2 · What one outlier does. A school club posted five videos. They got 40, 52, 55, 61 and 67 views. Then a sixth video got 925 views. What happened to the mean and to the median?
Create a strategyFind both centers for the five videos, then for all six. Six is an even count, so the median is the mean of the two middle values.
Apply the idea
| Five videos | All six videos |
| Add them all | 40 + 52 + 55 + 61 + 67 = 275 | 275 + 925 = 1,200 |
| Mean | 275 ÷ 5 = 55 | 1,200 ÷ 6 = 200 |
| Median | the third value, 55 | (55 + 61) ÷ 2 = 58 |
There are six values now, so divide by 6. The mean moved 145 views. The median moved 3 views.
Reflect and checkThe 925 is an outlier. Five of the six videos got fewer than 200 views, so the mean no longer describes a typical video. The median, 58 views, does. The 925 is a real count, so it stays in the data. You report the median, and you say why.
Try It: Move One Value
The lab starts on six new values. The solid line is the median and the dashed line is the mean. Change a value and watch which line moves. Then meet the three goals.
In Sheets: AVERAGE, MEDIAN and a Histogram
The same steps as in class, on the class file. Column G is weight, in kilograms.
- Download L17-YRBSS.csv.
- Open Google Sheets.
- Click Blank spreadsheet.
- File > Import > Upload > Browse.
- Pick L17-YRBSS.csv.
- Import location: Insert new sheet(s).
- Import data.
- Click cell N1. Type:
=AVERAGE(G2:G13584)
- Click cell N2. Type:
=MEDIAN(G2:G13584)
- Click the column G letter.
- Insert > Chart.
- On Setup, set Chart type to Histogram chart.
N1 shows the mean, 67.9 to one decimal place. N2 shows the median, 64.4. The chart has the same long tail to the right as the histogram above.
1,004 rows say NA in column G. =AVERAGE and =MEDIAN skip text, so they use the 12,579 weights that are numbers. If N1 shows 1.69, you picked column F, height in meters.
The Same in Python
Python comes in L19b, later in this cycle. Once you have read it, come back and run Example 2’s six videos here.
In Sheets this is: =AVERAGE(A1:A6) and =MEDIAN(A1:A6).
In English:
- Get the pandas toolbox and call it pd.
- Make a column of the six numbers, and call it views.
- Print the mean of views.
- Print the median of views.
Predict: Example 2 found both by hand. What will lines 3 and 4 print? Then change the 925 to 70, say which line will change more, and run it again.
Can’t run it here? Show what it prints
200.0
58.0
pandas writes a whole mean or median as a decimal: 200.0 and 58.0 are the 200 and the 58 from Example 2. With 70 in place of 925 it prints 57.5 and 58.0. The mean dropped by 142.5, and the median stayed.
Want to type your own? The Python practice page has tasks and a notebook.
In your project
Three pieces of your Cycle 2 project’s ANALYSIS tab come from this chapter: a histogram, the mean and the median of your number column. Make the histogram first and look for a tail. If it has a long tail, report the median first, and say why: a few far values pull the mean. If the mean and the median are close, either one describes a typical value.
A mean far from the median is also a warning. Look for a value typed wrong. Fix it on your CLEAN tab and write the fix on your LOG tab.
Check Yourself
Answer each one before you look. The first two are from L15 and L16.
Every line of a file looks like this: Leo;16;Room 8. You name the separator yourself. Which Separator type do you choose? L15
A ; sits between the values. The list has Tab and Comma but no ; of its own, so choose Custom and type ; in the box. With Comma, every line would land whole in column A.
A file of bus trips has one row a trip. Bus 12 is on 40 rows, each with its own date. Are those 40 rows duplicates? L16
A duplicate is a row that matches another in every column. The bus number is the id, and it repeats because one bus makes many trips. Each row has its own date, so no row is in the file twice. A big count does not make a duplicate.
Find the mean of 4, 9, 6, 13 and 8.
Add them all: 4 + 9 + 6 + 13 + 8 = 40. Divide by how many: 40 ÷ 5 = 8.
Find the median of 21, 7, 30, 15 and 12.
In order: 7, 12, 15, 21, 30. The middle of five values is the third: 15. The middle of the list as written is 30, the biggest value.
Six plants grew 1, 3, 7, 12, 16 and 19 cm in a month. Find the median, in centimeters.
The six values are in order. The two middle values are the third and the fourth, 7 and 12. (7 + 12) ÷ 2 = 9.5 cm. A median does not have to be one of the values.
Five tips at a cafe, in dollars: 2, 3, 4, 5, 6. Their mean is 4. A sixth tip of 40 comes in. What is the new mean?
2 + 3 + 4 + 5 + 6 + 40 = 60, and 60 ÷ 6 = 10. One tip moved the mean from $4 to $10. The median moved from $4 to $4.50: the two middle tips are now 4 and 5.
One value far from the rest joins a list. What does it do to the two centers?
The mean uses the size of every value, so one far value pulls it. The median uses only the order, so the middle barely moves.
Seven pizza deliveries took 18, 19, 20, 21, 22, 23 and 24 minutes. The mean is 21 and the median is 21. Which center describes a typical delivery?
No value sits far from the rest, so nothing pulls the mean away from the middle. 147 ÷ 7 = 21, and the fourth of the seven values is 21. When the mean and the median are close, either one describes a typical value.
A column holds 500 wait times. =AVERAGE gives 48 minutes and =MEDIAN gives 31 minutes. What does the histogram most likely show?
The mean sits above the median, so a few big values pull it up: a long tail to the right. The data are skewed right. A tail to the left would pull the mean below the median. With the same shape on both sides, the two would be close.
Project Checkpoint
ANALYSIS · part of P2, due Fri 18 Dec
Your claim reports a typical value for each group. The mean and the median are two ways to say typical, and a mean far from its median warns you that a few far values, or a typo, are pulling it.
Do these once your CLEAN tab exists (L22, Fri 4 Dec). Column B of CLEAN is your number.
Check these numbers in Python: Your Project File on the practice page opens your CLEAN tab and prints them.
Tick each step once it is in your Sheet. Your ticks go into the PDF you hand in. Where everything goes: your Sheet, tab by tab.
Stuck on any of this? Ask Mr. Case in class or send him a message in Canvas. Name the example or the question number, and say which step lost you.