How to get the nth percentile of a Pandas series?

A percentile is a statistical measure that indicates the value below which a certain percentage of observations fall. In Pandas, you can calculate the nth percentile of a series using the quantile() method.

Syntax

series.quantile(q)

Parameters:

  • q − The quantile value between 0 and 1 (percentile/100)

Example

Here's how to calculate the 50th percentile (median) of a Pandas series ?

import pandas as pd

# Create a Pandas series
series = pd.Series([10, 20, 30, 40, 50])
print("Series:")
print(series)

# Calculate 50th percentile
percentile_50 = series.quantile(0.5)
print(f"\nThe 50th percentile is: {percentile_50}")
Series:
0    10
1    20
2    30
3    40
4    50
dtype: int64

The 50th percentile is: 30.0

Multiple Percentiles

You can calculate multiple percentiles at once by passing a list ?

import pandas as pd

series = pd.Series([10, 20, 30, 40, 50, 60, 70, 80, 90, 100])

# Calculate multiple percentiles
percentiles = series.quantile([0.25, 0.5, 0.75, 0.9])
print("Multiple percentiles:")
print(percentiles)
Multiple percentiles:
0.25    32.5
0.50    55.0
0.75    77.5
0.90    91.0
dtype: float64

Real-World Example

Let's find percentiles for student test scores ?

import pandas as pd

# Student test scores
scores = pd.Series([85, 92, 78, 96, 88, 73, 91, 84, 89, 95])
print("Test Scores:")
print(scores.sort_values().values)

# Calculate various percentiles
print(f"\n25th percentile: {scores.quantile(0.25)}")
print(f"50th percentile (median): {scores.quantile(0.5)}")
print(f"75th percentile: {scores.quantile(0.75)}")
print(f"90th percentile: {scores.quantile(0.9)}")
Test Scores:
[73 78 84 85 88 89 91 92 95 96]

25th percentile: 82.75
50th percentile (median): 88.5
75th percentile: 92.25
90th percentile: 95.1

Key Points

  • The quantile() method accepts values between 0 and 1
  • To convert percentile to quantile: divide by 100 (50th percentile = 0.5)
  • The 50th percentile equals the median
  • Missing values are excluded by default

Conclusion

Use series.quantile(q) to find the nth percentile of a Pandas series. Convert percentile values to decimal form (divide by 100) before passing to the method.

Updated on: 2026-03-25T17:57:27+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements