← Back to NumPy Course | Chapter 8: Statistics | Lesson 2 of 6

np.percentile/quantile

Percentiles tell you the value below which a given share of the data falls.

In this page:

  1. np.percentile/quantile
Syntax
python
np.percentile(arr, q)
np.quantile(arr, fraction)

np.percentile/quantile

np.percentile(a, 90) finds the value with 90 percent of the data at or below it. np.quantile does the same using fractions from 0 to 1. The 50th percentile is the median, and the gap between the 75th and 25th is the interquartile range.

Note: Pass a list such as [25, 50, 75] to get several at once.

Example: np.percentile/quantile

python
import numpy as np

scores = np.array([55, 60, 65, 70, 75, 80, 85, 90, 95, 100])
print(np.percentile(scores, 50))
print(np.percentile(scores, [25, 75]))
print(np.quantile(scores, 0.9))

# Output:
# 77.5
# [66.25 88.75]
# 95.5
Related Topics
Common Mistakes
  1. Mixing percent (0-100) with quantile fractions (0-1)
  2. Forgetting interpolation between values
  3. Confusing percentile with percentage
Chapter Summary
  • percentile uses 0 to 100
  • quantile uses 0 to 1
  • 50th percentile is the median
  • IQR = Q3 minus Q1
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.