np.percentile/quantile
Percentiles tell you the value below which a given share of the data falls.
In this page:
Syntax
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
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
- Mixing percent (0-100) with quantile fractions (0-1)
- Forgetting interpolation between values
- 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: