- 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
- If you look at the API for
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 OverflowPandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.quantile.html
pandas.DataFrame.quantile — pandas 3.0.6 documentation
Numpy function to compute the percentile.
11:24
Understanding Quantiles in Python: A Step-by-Step Guide (Numpy ...
06:22
Quantile in Python (4 Examples) | Calculate Quartile, Decile & ...
11:08
DataFrame Percentile Quartiles using Numpy, Pandas, & Python - YouTube
21:31
How to Calculate Percentiles in Python: np.percentile() - YouTube
PROGRAM#12 | HOW TO SLICE SERIES IN PYTHON | HOW TO CALCULATE ...
02:52
Quantile for a numerical feature using pandas - YouTube
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
- If you look at the API for
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
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.DataFrame.quantile.html
pandas.DataFrame.quantile — pandas 3.0.5 documentation
Numpy function to compute the percentile.
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.
Skytowner
skytowner.com › explore › calculating_percentiles_of_a_dataframe_in_pandas
Calculating percentiles of a DataFrame in Pandas
To calculate percentiles in Pandas, use the quantile(~) method.
Pandas
pandas.pydata.org › docs › reference › api › pandas.Series.quantile.html
pandas.Series.quantile — pandas 3.0.6 documentation
Calculate the rolling quantile. ... Returns the q-th percentile(s) of the array elements.
Pandas
pandas.pydata.org › pandas-docs › stable › reference › api › pandas.Series.quantile.html
pandas.Series.quantile — pandas 3.0.5 documentation
Calculate the rolling quantile. ... Returns the q-th percentile(s) of the array elements.
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.
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.
TutorialsPoint
tutorialspoint.com › article › percentile-rank-of-a-column-in-a-pandas-dataframe
Percentile Rank of a Column in a Pandas DataFrame
March 27, 2026 - Use rank(pct=True) for simple percentile rank calculations in pandas.