Q&A library Python

How do I see custom percentiles in describe in pandas?

Python Intermediate describepercentilessummary

Short answer

Pass a percentiles list to describe to see the ones you care about, such as the 90th and 99th. The defaults hide the tail, which is exactly where the interesting behaviour usually is.

The short version

describe() shows the 25th, 50th and 75th percentiles by default. Pass percentiles=[...] to see others, such as the 90th or 99th. The default view hides the tail, which is often precisely where the behaviour that matters lives.

Choosing your percentiles

import pandas as pd

s = pd.Series([1, 2, 3, 4])

s.describe(percentiles=[0.9])

The output now includes a 90% row alongside the count, mean, standard deviation, min and max. The median is always included, whatever you ask for, because describe treats it as essential.

s.describe(percentiles=[0.05, 0.5, 0.95, 0.99])

Why the tail matters

For anything with a long tail (response times, order values, file sizes), the mean and the quartiles tell you almost nothing about the worst cases. A system whose median response is 100 milliseconds might have a 99th percentile of ten seconds, and it is the 99th that your users complain about.

The default describe would show you the reassuring middle and hide the problem entirely. Asking for the tail explicitly is how you find it.

Include text columns too

By default describe covers only numeric columns, silently ignoring everything else.

df.describe(include="all")

This adds a summary for text columns: the number of distinct values, the most frequent one and its count. That gives you a fast profile of the categorical columns alongside the numeric ones, which is why it is a good first command on an unfamiliar dataset.

Per group

describe works after a groupby, giving a full summary for each group.

df.groupby("city")["amount"].describe()

This is a quick way to compare distributions across groups, and it often reveals that a difference in means is really a difference in spread or in outliers.

Mean versus median

A useful habit when reading describe: compare the mean with the 50 per cent row. If the mean is much higher, the distribution is skewed right, meaning a few large values are pulling it up, and the median is the more honest summary. If they are close, the mean is a reasonable representative value.

That single comparison, available for free in every describe output, tells you more about whether to trust a mean than almost anything else.

It is a starting point, not a conclusion

describe summarises; it does not show shape. Two very different distributions can produce similar summary statistics. Always plot a histogram as well, because the picture routinely shows things (a second peak, a spike at zero, an impossible value) that no table of statistics reveals.

Need this solved on your own data?

The library is free and always will be. When the problem is bigger than an answer, we take on the work.

Start a project