liveBook · Manning

Quantiles

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

A quantile is a value that divides an ordered dataset so that a specified proportion of observations falls at or below it.

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

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

How deep it goes
Explains 25%, 50%, and 75% positions and applies `quantile` in Series and selected DataFrame columns.
Examples
Practices normal-distribution summaries, taxi-trip-distance outliers, and university tuition and Pell-grant threshold filters.
What it assumes
Assumes familiarity with pandas Series, DataFrame columns, and boolean indexing while explaining quartile positions directly.
What you can do after
Apply it via pandas `quantile` to summarize columns, calculate IQR bounds, and select rows above or below quartile thresholds.
How it connects
Connects quantiles to descriptive statistics, median, interquartile range, outliers, boolean indexing, and DataFrames.

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.