Percentiles and Quartiles
Maths: Statistics for machine learning
2 min read
This section is 2 min read, full guide is 105 min read
Published Oct 22 2025, updated Oct 23 2025
40
Show sections list
0
Log in to enable the "Like" button
0
Guide comments
0
Log in to enable the "Save" button
Respond to this guide
Guide Sections
Guide Comments
Machine LearningMathsNumPyPandasPythonStatistics
Percentiles and quartiles are measures of position (or location) in a dataset.
They show how data values are distributed and help you understand where a particular value stands relative to the rest of the data.
In simple terms:
- Percentiles divide your data into 100 equal parts
- Quartiles divide your data into 4 equal parts
Both are used to describe data spread and relative standing within a dataset.
Percentiles
What Is a Percentile?
A percentile indicates the value below which a certain percentage of observations fall.
For example:
- The 25th percentile (P25) is the value below which 25% of the data fall.
- The 50th percentile (P50) is the median — 50% of data are below it.
- The 90th percentile (P90) is the value below which 90% of data fall.
So if your exam score is at the 90th percentile, you scored better than 90% of people.
Example:
Data (ordered): [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
- P25 (25th percentile) = 25% of 10 = 2.5 → halfway between 2nd and 3rd value
→ (20 + 30)/2 = 25 - P50 (50th percentile) = median = 55
- P75 (75th percentile) = 7.5th position → halfway between 7th and 8th values
→ (70 + 80)/2 = 75
Quartiles
What Are Quartiles?
Quartiles are specific percentiles that divide data into four equal parts:
- Q1 - 25th percentile (P25) - 25% of data are below this value.
- Q2 - 50th percentile (P50) - Median — half the data below, half above.
- Q3 - 75th percentile (P75) - 75% of data are below this value.
Calculating in Python
In NumPy:
import numpy as np
data = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
q1 = np.quantile(data, 0.25)
q2 = np.quantile(data, 0.5)
q3 = np.quantile(data, 0.75)
print("Q1 (25th percentile):", q1)
print("Q2 (Median, 50th percentile):", q2)
print("Q3 (75th percentile):", q3)
Copy to Clipboard
In Pandas:
import pandas as pd
data = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
s = pd.Series(data)
q1 = s.quantile(0.25)
q2 = s.quantile(0.5)
q3 = s.quantile(0.75)
print("Q1:", q1)
print("Median (Q2):", q2)
print("Q3:", q3)
Copy to Clipboard














