Calculate each channel’s 90th percentile with groupby().quantile(0.90, interpolation="linear"). In this fictional support log, Chat’s cutoff is 9.4 minutes and Phone’s is 11.4. Show the number of measured responses beside each cutoff.

One Chat record and the only Email record lack a response time. We keep those rows in the source count, calculate percentiles from measured durations, and leave Email’s cutoff missing.

Chat response times 4, 6, 8, and 10 minutes give an interpolated p90 of 9.4. Phone times 6, 8, 10, and 12 give 11.4. Email has no measured duration and no percentile.
The diamonds mark interpolated cutoffs, not observed response times. Original hypothetical support data.Credit: MathBlog

Start with comparable response times

Each row represents one request from the same hypothetical reporting period. All durations use minutes from receipt of the request to the first reply. Missing means the duration was not recorded; it does not mean the reply was instant.

Original hypothetical support requests; Missing becomes None in the Python data
Request Channel Minutes
C01 Chat 4
C02 Chat 6
C03 Chat 8
C04 Chat 10
C05 Chat Missing
P01 Phone 6
P02 Phone 8
P03 Phone 10
P04 Phone 12
E01 Email Missing

Repeated export rows would give those observations extra weight. Check duplicated records before calculating percentiles if your exports can overlap, using a rule that preserves legitimate requests.

Calculate the cutoff and its measurement count

Run the complete example in a Python session with pandas installed. This example was run with Python 3.11.3 and pandas 2.3.3.

from math import isfinite

import pandas as pd


def p90_by_channel(frame):
    data = frame.copy()
    labels = data["channel"].astype("string")
    bad_label = labels.isna() | labels.str.strip().eq("")
    padded_label = labels.notna() & labels.ne(labels.str.strip())
    if (bad_label | padded_label).any():
        raise ValueError("Use nonblank channel names without surrounding spaces.")
    data["channel"] = labels
    data["minutes"] = pd.to_numeric(data["minutes"], errors="raise")
    known = data["minutes"].dropna()
    if known.lt(0).any() or not known.map(isfinite).all():
        raise ValueError("Measured minutes must be finite and nonnegative.")

    groups = data.groupby("channel", sort=True, observed=True)
    summary = groups["minutes"].agg(source_rows="size", measured="count")
    summary["missing"] = summary["source_rows"] - summary["measured"]
    summary["p90_minutes"] = groups["minutes"].quantile(
        0.90, interpolation="linear"
    )
    return summary.reset_index()


responses = pd.DataFrame({
    "request_id": ["C01", "C02", "C03", "C04", "C05",
                   "P01", "P02", "P03", "P04", "E01"],
    "channel": ["Chat"] * 5 + ["Phone"] * 4 + ["Email"],
    "minutes": [4, 6, 8, 10, None, 6, 8, 10, 12, None],
})
summary = p90_by_channel(responses)
print(summary.to_string(
    index=False, na_rep="Missing", float_format=lambda value: f"{value:.1f}"
))

Output from the tested runtime:

channel  source_rows  measured  missing  p90_minutes
   Chat            5         4        1          9.4
  Email            1         0        1      Missing
  Phone            4         4        0         11.4

size counts every source row. count counts nonmissing durations, and their difference gives the missing count. The quantile call uses 0.90, not 90, because its probability argument runs from 0 to 1.

The function copies its input. Numeric parsing uses to_numeric(..., errors="raise") so invalid numeric text stops the calculation. Blank or padded channel names also stop it. Python’s isfinite() check rejects infinite measured durations, and negative durations are rejected separately.

Check what linear interpolation means

Chat has four measured durations, sorted as 4, 6, 8, and 10. The linear rule uses the zero-based position \(h=(n-1)q=3(0.90)=2.7\). Position 2 is the third value, 8; position 3 is the fourth, 10. The requested cutoff lies 70% of the way between them:

\[8+0.7(10-8)=9.4\text{ minutes}.\]

For Phone, the corresponding values are 10 and 12, giving \(10+0.7(12-10)=11.4\) minutes. Neither result has to be an observed response time. Keep the interpolation rule with the report: another rule, such as selecting the higher observation, answers the sample-percentile question differently.

Only three of Chat’s four measurements are at or below 9.4. An interpolated sample percentile does not require exactly 90% of a short list to fall below it. For the related question of where one recorded score ranks, see why the same score can have three percentile ranks.

Read the missing counts before comparing channels

Chat’s percentile uses four measurements from five records. Phone’s uses four from four. Email has one record but no measurement, so its percentile remains missing. Filling that duration with zero would create an observation that the source never supplied. A genuine recorded zero is allowed by this example’s nonnegative-duration rule.

The function returns no rows for an empty input with the required columns. It does not invent channels that never appear in the input. Check a failed or incomplete import before treating an empty summary as a complete report.

Use the same time window, units, inclusion rules, and interpolation method when comparing real channels. If missing durations represent requests still awaiting a reply, excluding them can make a report look faster; investigate that meaning before relying on the percentiles. Four measured responses are enough to check this code, but they do not establish a stable service benchmark or guarantee a future response time.

Further reading