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






