liveBook · Manning

Interquartile range

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

The interquartile range is the difference between the 75th-percentile and 25th-percentile values of an ordered dataset.

The interquartile range (IQR) measures the spread of the middle half of an ordered dataset: subtract the 25th-percentile value from the 75th-percentile value. It also provides a practical rule for flagging unusually low or high values. section 2.17

A common IQR-based outlier check uses these steps:

  • Calculate Q1 with quantile(0.25) and Q3 with quantile(0.75). section 2.18
  • Subtract Q1 from Q3 to obtain the IQR. section 2.18
  • Flag values below Q1 − 1.5 × IQR or above Q3 + 1.5 × IQR. section 2.17
  • Apply the resulting boolean condition to the relevant rows, then analyze another column for those observations. section 2.18

Taxi-trip distances

Build a DataFrame from trip distances and passenger counts, then calculate the distance IQR from the trip_distance Series. Filtering below the lower boundary finds no outliers, while filtering above the upper boundary finds 1,889 outliers among 10,000 rides. Use the matching passenger_count values and their mean to compare unusually long trips with all trips. section 2.18

df['mintemp'].plot.box()

A boxplot uses the five-number summary and marks observations at least 1.5 IQR below Q1 or above Q3, making IQR-based outliers visible. section 11.6

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Defines IQR, derives percentile thresholds, filters rows, and visualizes results with boxplots without developing alternative statistical theory.
Examples
Works through taxi distances and passenger counts, then examines Chicago temperature outliers with boxplots.
What it assumes
Assumes familiarity with pandas Series and DataFrames while demonstrating how to combine Series and select filtered rows.
What you can do after
Apply via pandas by calculating quantiles, filtering IQR-based outliers, and comparing selected rows with the full dataset.
How it connects
Connects quantiles, outliers, boolean filtering, DataFrames, Series, and boxplots.

Also explained in

Compare how 7 books explain interquartile range →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.