Module 7 · Statistics: Describing and Deciding · Lesson 22 of 51

Centre, spread and outliers

Mean, median and mode; range, variance, standard deviation and IQR; percentiles; and two ways to flag outliers, with when to use which.

In this lesson · about 40 minutes

  • Choose between mean and median for a given column
  • Measure spread with standard deviation and IQR, and explain them in words
  • Flag outliers with the 1.5 × IQR rule and with z-scores

Centre

  • Mean: the sum divided by the count. Uses every value, so one extreme value drags it.
  • Median: the middle value when sorted (the 50th percentile). Robust to outliers: report it for skewed things like spend, income, house prices, wait times.
  • Mode: the most common value. Useful for categories ("most common item: Latte").

Spread

  • Range = max − min. Simple, but one odd value changes it.
  • Variance: the average squared distance from the mean. Standard deviation (SD) is its square root, back in the original units: "orders are typically about $3.40 away from the average". pandas uses the sample version (divides by n − 1).
  • Percentiles: the 90th percentile is the value 90% of the data is below. Quartiles are the 25th (Q1), 50th (median) and 75th (Q3). IQR = Q3 − Q1, the range of the middle half: a robust spread.

Outliers

  • IQR rule: below Q1 − 1.5 × IQR or above Q3 + 1.5 × IQR (the box-plot dots). Works for skewed data.
  • z-score: (value − mean) ÷ SD, i.e. how many SDs from the mean. |z| > 3 is unusual for roughly bell-shaped data.

An outlier is a question, not a delete key: a $48 order might be a typo, or your best catering customer. Investigate, then decide, then log it.

Try it · data lab

Shape, centre and spread

120 order totals. Stretch the spread, add a long tail and drop in one huge order, and watch what happens to the mean, the median and the box plot.

07.51522.530Order total ($)mean 7.12median 7.08Q1 5.8median 7.1Q3 8.3Order total ($) · 2 outliers (red)

Mean

7.12

Median

7.08

Std deviation

1.94

IQR (Q3 − Q1)

2.45

Mean and median are close: the data is roughly symmetric, so either describes the typical order.

describe(), quantiles and outliers

Exercise

Describe Riverside's days

For Riverside's daily sales (rs), set avg to the mean, mid to the median, sd to the standard deviation and iqr to Q3 − Q1. Round each to 2 decimals.

Code that runs before yours
import pandas as pd
import numpy as np
daily = pd.read_csv("kc_daily.csv", parse_dates=["date"])
rs = daily.loc[daily["branch"] == "Riverside", "sales"]

Exercise

Unusual days by z-score

Add a column z to dt (Downtown's days): each day's sales as a z-score, (sales − mean) / std. Then set unusual to the number of days with |z| > 2.

Code that runs before yours
import pandas as pd
import numpy as np
daily = pd.read_csv("kc_daily.csv", parse_dates=["date"])
dt = daily[daily["branch"] == "Downtown"].copy()

Check your understanding0 of 3 correct

Question 1

1.Member spend is strongly right-skewed. Which 'typical spend' should you report?

Question 2

2.SD of order totals is $3.40. In words:

Question 3

3.Q1 = 4, Q3 = 9. Using the 1.5 × IQR rule, which is an outlier?

Quiz score: 0 of 3

Exercises solved: 0 of 2

Tip: answer every quiz question correctly first.

Written by Noviq Academy in its own words. Kettle & Crumb and all its data are made up for teaching; any resemblance to a real business is a coincidence. Python runs in your browser with Pyodide, so results can differ slightly from your own computer. Power BI, Tableau and other product names belong to their owners. Read-aloud uses your device's built-in voices.