Python Glossary Русский

Python 3.8+Numbers & mathfunction

statistics.quantiles()

statistics

Computes the quantiles of a data set. n=4 → quartiles, n=100 → percentiles.

Syntax

statistics.quantiles(data, *, n=4, method='exclusive')

You get n-1 cut points, not n: with n=4 that is three quartiles, not four numbers. The default method='exclusive' treats the data as a sample drawn from a larger population, so results will not match numpy.percentile, whose default behaves closer to method='inclusive' — pass that when your data is the whole population. Empty data raises StatisticsError; a single data point is accepted since Python 3.13 (it used to be an error too). n and method are keyword-only.

Examples

import statistics
data = list(range(1, 11))
statistics.quantiles(data, n=4) # → [3.25, 5.5, 7.75]
statistics.quantiles(data, n=2) # → [5.5]  медиана
statistics.quantiles([1,2,3,4,5,6,7,8,9,10], n=10)
# → [1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1]

See also

Open in the full glossarydocs.python.orgReport an inaccuracy