Python Glossary Русский

Python 3.4+statisticsterm

statistics

module

Descriptive statistics for numeric data: mean, median, mode, variance, correlation.

Syntax

import statistics

statistics covers school-level and basic applied statistics without third-party libraries and computes exactly, including with Fraction and Decimal. It is slow on large arrays — reach for NumPy there. A frequent mix-up: stdev and variance are sample statistics (dividing by n-1), while pstdev and pvariance describe a whole population; for float data fmean is faster.

Examples

import statistics
data = [2, 4, 4, 4, 5, 5, 7, 9]
print(statistics.mean(data), statistics.median(data))  # → 5 4.5
print(statistics.mode(data), statistics.pstdev(data))  # → 4 2.0

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy