An outlier is an observation unusually far below or above a dataset’s central range. Because no single definition fits every dataset, choose a criterion that matches the question. section 2.17
A common rule uses the interquartile range (IQR): values below Q1 − 1.5 × IQR or above Q3 + 1.5 × IQR are outliers. Mean-and-standard-deviation or z-score rules are alternatives. section 2.17 section 2.20
Work through an outlier analysis in four steps:
- Create a DataFrame from aligned series, such as trip distances and passenger counts. section 2.18
- Calculate Q1, Q3, and the IQR for the column being examined; do not calculate quantiles for unrelated columns. section 2.18
- Filter rows with a Boolean condition for unusually low or high values. section 2.18
- Use the selected rows to compare related measures, such as passenger counts for unusual trips versus all trips. section 2.17
Taxi-trip distances
For 10,000 taxi rides, the IQR rule finds no low-distance outliers but identifies 1,889 high-distance outliers—about 19% of rides. The next analysis compares their passenger count with the overall mean. section 2.18 section 2.17
Temperature boxplots
A boxplot marks Chicago minimum temperatures at least 1.5 × IQR beyond the quartiles. Readings of −27°C and −28°C on January 30 and 31 appear as unusually cold values. section 11.6
iqr = (
df['trip_distance'].quantile(0.75) -
df['trip_distance'].quantile(0.25)
)
Calculate the IQR directly from the selected DataFrame column before applying the outlier bounds. section 2.18













