• You can use the pandas.DataFrame.quantile() function.
    • If you look at the API for quantile(), you will see it takes an argument for how to do interpolation. If you want a quantile that falls between two positions in your data:
      • 'linear', 'lower', 'higher', 'midpoint', or 'nearest'.
      • By default, it performs linear interpolation.
      • These interpolation methods are discussed in the Wikipedia article for percentile
import pandas as pd
import numpy as np

# sample data 
np.random.seed(2023)  # for reproducibility
data = {'Category': np.random.choice(['hot', 'cold'], size=(10,)),
        'field_A': np.random.randint(0, 100, size=(10,)),
        'field_B': np.random.randint(0, 100, size=(10,))}
df = pd.DataFrame(data)

df.field_A.mean()  # Same as df['field_A'].mean()
# 51.1

df.field_A.median() 
# 50.0

# You can call `quantile(i)` to get the i'th quantile,
# where `i` should be a fractional number.

df.field_A.quantile(0.1)  # 10th percentile
# 15.6

df.field_A.quantile(0.5)  # same as median
# 50.0

df.field_A.quantile(0.9)  # 90th percentile
# 88.8

df.groupby('Category').field_A.quantile(0.1)
#Category
#cold    28.8
#hot      8.6
#Name: field_A, dtype: float64

df

  Category  field_A  field_B
0     cold       96       58
1     cold       22       28
2      hot       17       81
3     cold       53       71
4     cold       47       63
5      hot       77       48
6     cold       39       32
7      hot       69       29
8      hot       88       49
9      hot        3       49
Answer from stackoverflowuser2010 on Stack Overflow
🌐
datagy
datagy.io › home › pandas tutorials › data analysis in pandas › pandas quantile: calculate percentiles of a dataframe
Pandas Quantile: Calculate Percentiles of a Dataframe • datagy
April 16, 2023 - Let’s take a look at what the method looks like and what parameters the quantile method provides: # Understanding the Pandas .quantile() method to calculate percentiles df.quantile( q=0.5, # The percentile to calculate axis=0, # The axis to ...
Top answer
1 of 6
183
  • You can use the pandas.DataFrame.quantile() function.
    • If you look at the API for quantile(), you will see it takes an argument for how to do interpolation. If you want a quantile that falls between two positions in your data:
      • 'linear', 'lower', 'higher', 'midpoint', or 'nearest'.
      • By default, it performs linear interpolation.
      • These interpolation methods are discussed in the Wikipedia article for percentile
import pandas as pd
import numpy as np

# sample data 
np.random.seed(2023)  # for reproducibility
data = {'Category': np.random.choice(['hot', 'cold'], size=(10,)),
        'field_A': np.random.randint(0, 100, size=(10,)),
        'field_B': np.random.randint(0, 100, size=(10,))}
df = pd.DataFrame(data)

df.field_A.mean()  # Same as df['field_A'].mean()
# 51.1

df.field_A.median() 
# 50.0

# You can call `quantile(i)` to get the i'th quantile,
# where `i` should be a fractional number.

df.field_A.quantile(0.1)  # 10th percentile
# 15.6

df.field_A.quantile(0.5)  # same as median
# 50.0

df.field_A.quantile(0.9)  # 90th percentile
# 88.8

df.groupby('Category').field_A.quantile(0.1)
#Category
#cold    28.8
#hot      8.6
#Name: field_A, dtype: float64

df

  Category  field_A  field_B
0     cold       96       58
1     cold       22       28
2      hot       17       81
3     cold       53       71
4     cold       47       63
5      hot       77       48
6     cold       39       32
7      hot       69       29
8      hot       88       49
9      hot        3       49
2 of 6
39

assume series s

s = pd.Series(np.arange(100))

Get quantiles for [.1, .2, .3, .4, .5, .6, .7, .8, .9]

s.quantile(np.linspace(.1, 1, 9, 0))

0.1     9.9
0.2    19.8
0.3    29.7
0.4    39.6
0.5    49.5
0.6    59.4
0.7    69.3
0.8    79.2
0.9    89.1
dtype: float64

OR

s.quantile(np.linspace(.1, 1, 9, 0), 'lower')

0.1     9
0.2    19
0.3    29
0.4    39
0.5    49
0.6    59
0.7    69
0.8    79
0.9    89
dtype: int32
🌐
Data Science Parichay
datascienceparichay.com › home › blog › calculate percentile in python
Calculate Percentile in Python - Data Science Parichay
October 9, 2021 - # using numpy - 95th percentile value of the array arr np.percentile(arr, 95) # using pandas - 95th percentile value of column 'Col' in df df['Col'].quantile(0.95) Let’s look at some examples of using the above syntax to get the percentiles in Python. To get the nth percentile value of an array or a list, pass the array (or list) along with the value of n (the percentile you want to calculate) to the numpy’s percentile() function.
🌐
Medium
medium.com › @amit25173 › understanding-percentiles-in-pandas-369166d19e76
Understanding Percentiles in Pandas | by Amit Yadav | Medium
March 6, 2025 - Using numpy.percentile() (since pandas relies on NumPy) Let’s get straight to the point. If you’re dealing with percentiles in Python, NumPy’s percentile() is your go-to tool. It’s fast, simple, and perfect for quick calculations.
🌐
GeeksforGeeks
geeksforgeeks.org › python › calculate-arbitrary-percentile-on-pandas-groupby
Calculate Arbitrary Percentile on Pandas GroupBy - GeeksforGeeks
July 23, 2025 - In Pandas, we can easily compute percentiles using the quantile() function. It can also be calculated using the NumPy percentile() function.
Find elsewhere
🌐
Statology
statology.org › home › how to calculate percentiles in python (with examples)
How to Calculate Percentiles in Python (With Examples)
November 3, 2020 - For example, the 90th percentile of a dataset is the value that cuts of the bottom 90% of the data values from the top 10% of data values. We can quickly calculate percentiles in Python by using the numpy.percentile() function, which uses the ...
🌐
GeeksforGeeks
geeksforgeeks.org › percentile-rank-of-a-column-in-a-pandas-dataframe
Percentile rank of a column in a Pandas DataFrame - GeeksforGeeks
August 17, 2020 - Let us see how to find the percentile rank of a column in a Pandas DataFrame. We will use the rank() function with the argument pct = True to find the percentile rank.
🌐
Statology
statology.org › home › how to calculate percentile rank in pandas (with examples)
How to Calculate Percentile Rank in Pandas (With Examples)
August 30, 2022 - The following code shows how to calculate the percentile rank of each value in the points column, grouped by team:
🌐
Ryan Nolan Data
ryanandmattdatascience.com › home › statistics › python quantiles statistics
Calculate Quantiles & Percentiles in Python (Pandas)
July 24, 2025 - Pandas is used for data manipulation, data analysis and also for working with tabular data · Here, we define a list of numbers and we store it in a variable called data. Calculate Quartiles · np.percentile(data, 25) gives the value below which 25% of the data falls.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-find-percentile-stats-of-a-given-column-using-pandas
How to Find Percentile Stats of a Given Column Using Pandas | Saturn Cloud Blog
May 1, 2026 - Use the quantile() function to find the percentile statistics. Let’s dive into each step in detail. To use Pandas, we first need to import the library.
🌐
Enterprise DNA
blog.enterprisedna.co › pandas-percentile-calculate-percentiles-of-a-dataframe
Enterprise DNA: We Help Businesses Put Data and AI to Work
Learn data and AI skills on the platform, bring us in on a project, or run a managed Omni Command Centre. 220K+ professionals trained, 1,500+ companies impacted globally.
🌐
Statology
statology.org › home › pandas: how to use describe() with specific percentiles
Pandas: How to Use describe() with Specific Percentiles
March 8, 2023 - Notice that the describe() function calculates the 25th, 50th and 75th percentiles for each variable by default.
🌐
DataScience Made Simple
datasciencemadesimple.com › home › percentile rank of a column in pandas python – (percentile value)
Percentile rank of a column in pandas python - (percentile value) - DataScience Made Simple
November 15, 2019 - df1['Percentile_rank']=df1.Mathematics_score.rank(pct=True) print(df1) ... With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.
🌐
Scicoding
scicoding.com › calculating-percentiles-in-python
How to Calculate Percentiles in Python: 4 Different Methods
February 20, 2023 - Pandas support computing percentile via quantile method, which is readily available for pandas Series.