A quantile marks a position in ordered values: the 25% quantile is 25% of the way from the smallest value, the 50% quantile is the median, and the 75% quantile is 75% of the way through. They make a compact description of a distribution alongside count, mean, standard deviation, minimum, and maximum. section 1.15
For a pandas Series, use quantile with a proportion such as 0.25, 0.5, or 0.75. `describe()` collects these common quartiles with other descriptive statistics, which is useful when first inspecting a numeric Series. section 1.15
Find taxi-distance outlier thresholds
The interquartile range (IQR) is the 75th-quantile value minus the 25th-quantile value. Select the relevant column before calling `quantile`; calling it on a whole DataFrame returns a quantile for every column. Then use boolean indexing to retrieve distances below `Q1 - 1.5 * IQR` or above `Q3 + 1.5 * IQR`. `iqr = (df['trip_distance'].quantile(0.75) - df['trip_distance'].quantile(0.25))` section 2.18
iqr = (
df['trip_distance'].quantile(0.75) -
df['trip_distance'].quantile(0.25)
)
This calculation isolates the two quartiles for `trip_distance`, making the IQR explicit before it is used as an outlier boundary. section 2.18
Quantiles also turn broad questions into relative thresholds. To find institutions that are high on both tuition and Pell-grant participation, compare each relevant column with its own 0.75 quantile, combine the conditions with `&`, and select the matching rows with `.loc`. Similarly, a low-cost, high-earnings search can pair a 0.25 threshold in one column with a 0.75 threshold in another. section 13.3
When working with quartiles, keep the data shape and comparison direction clear:
- Use 0.25, 0.5, and 0.75 for the first quartile, median, and third quartile. section 1.15
- Compute a threshold from the same Series whose values you will compare. section 2.18
- Use `>` for values above a top-quartile cutoff and `<=` when selecting values at or below a bottom-quartile cutoff. section 13.3
