…
…
Find the outlier days in a 60-day delay record of campus shuttle routes with IQR and the z-score, fix the clear errors, keep the real extreme days, and show whether the median and the trimmed mean change the "most punctual route" ranking.
You are an intern in a university's campus transport office. At the end of the term, the office wants to announce to students: "Which shuttle route is the most punctual?" A ranking is already available: the mean delay of each route. But the table has days with delays of several hours, and notes about snowfall and roadwork. You are asked to find the outlier days, decide for each one whether to delete, fix, keep or flag it and explain why, and show whether this decision changes the ranking.
Data: shuttle_delays.csv (fictional sample data), 60 working days of four shuttle routes; each row is one day of one route.
| Column | Description |
|---|---|
date | Working day (between 2026-02-16 and 2026-05-08) |
route | Shuttle route: Red, Blue, Green or Yellow |
delay_min | The mean delay of that route's trips that day (minutes) |
event | The note the transport office wrote for that day (empty on most days) |
Lessons used: reading CSV, filtering, sorting and grouping (4–7), mean and median (12), standard deviation (14), quartiles, percentiles and IQR (15), z-score (16), missing values (19), outliers: the IQR rule, the business rule and the four decisions (21). The project has one new concept, the trimmed mean; step 7 gives its definition and calculation with the tools you have learned.
Cells share one session: each step works with df and the variables defined by the one before.
What you'll do
shuttle_delays.csvDownload file
Reading file…
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
You are an intern in a university's campus transport office. At the end of the term, the office wants to announce to students: "Which shuttle route is the most punctual?" The table you have is shuttle_delays.csv: the daily mean delay of four shuttle routes over 60 working days (fictional sample data).
First get to know the table: how many rows are there, how many days of records does each route have, and which notes appear in the event column? The event column is empty on most days; empty cells are left out when you count.
Finally, look at the largest delay. A campus shuttle leaves once an hour; does this number look reasonable to you?
This step's code cell is for members.Sign up free
A colleague in the office has already made a ranking: the mean delay of each route, from smallest to largest. Build the same table and take the route that looks most punctual as raw_best.
This table comes from data that has not been touched yet. Write the ranking down; as you check the data step by step, we will see whether it changes. Also compare Blue Route's mean with its median: what does the difference tell you?
This step's code cell is for members.
Code cells are for members
You can read the steps. Sign up free to run the code, complete the steps and save your progress.
Blue Route's mean is three times its median: a few days must be pulling the mean up. Flag outlier candidates with the IQR rule from lesson 21: below Q1 − 1.5 × IQR and above Q3 + 1.5 × IQR. Compute the fences from the delays of all days.
Keep the candidates in a column named iqr_flag, then list the flagged days from the largest delay to the smallest. As you read the list, look for three kinds of days: days with a note, days without a note that are very large, and days without a note that are only a little above the fence. Do not delete or fix anything yet: a candidate is an alarm, not a verdict.
This step's code cell is for members.Sign up free
Someone in the office objects: "We always use the z-score; above 3 is an outlier." Compute the z-score of each day (lesson 16): how many standard deviations the delay is from the mean. Then look at how many days the z > 3 rule flags, how many days IQR catches that z misses, and the largest z-score among the snowfall days.
On a snowfall day, the delay is 25–35 minutes: four or five times a normal day. Why does the z-score still stay small? Write your answer as a letter in the variable reason:
This step's code cell is for members.Sign up free
The four days that z caught are the four largest values: 162, 246, 252 and 276 minutes. The transport office says this: the shuttle leaves every hour; if a day's mean delay goes above 60 minutes, that day's trips count as canceled and do not enter the table. There is a note too: on some days the GPS device broke and the delay was typed in by hand, and a few records were written in seconds.
This is a business rule: values above 60 minutes cannot exist, and the right value is known (divide the seconds by 60). Fix these rows, then recompute the mean for each route and see how the ranking changes. The means from before the fix are stored in raw from step 2.
This step's code cell is for members.Sign up free
The clear errors are fixed, and the fences have changed too, because the errors were pushing the quartiles up a little. Recompute the IQR fences on the fixed data and flag the remaining outliers in an outlier column. Then count these days by their event note; label the days without a note as "no explanation".
For each group, give one of the four decisions from lesson 21: fix, remove, keep or flag. Write your decision in the decision dictionary as "fix", "remove", "keep" or "flag". Ask yourself: did students really wait at the stop that day? Is the correct value known? What do you do with a day when you do not know the reason?
This step's code cell is for members.Sign up free
The outlier days will stay, but you have to pick one number. For each route, put four summaries side by side:
outlier left out (the "without" calculation from lesson 21),The trimmed mean is a compromise between the mean and the median: it drops the ends but uses all of the middle days. When the table is ready, see which summary moves which route the most.
This step's code cell is for members.Sign up free
Now return to the real question: which route is the most punctual? Sort the routes from smallest to largest by each column of the summary table and keep each ranking in the rankings dictionary. Then print them together with the raw ranking from step 2.
When you look at the rankings, separate two things: which result stays the same in every summary, and which result changes with the summary you pick? If the result changes with the summary, how solid would it be to announce a single route as "the most punctual"?
The cell then prints six sentences. For each one, ask: does this data and this analysis really show it? Write the letters of the ones it shows in the list says, and the letters of the ones it does not show in the list does_not_say.
This step's code cell is for members.Sign up free