Percentiles and Quartiles

Maths: Statistics for machine learning

2 min read

Published Oct 22 2025, updated Oct 23 2025


40
0
0
0

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)

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)

Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact