← All notes

Python statistics - mean, median, stdev, quantiles and correlation without NumPy

Answer: mean() returns the sample arithmetic mean, median() the middle value, and stdev() the sample standard deviation. The module calculates mathematical statistics of numeric data and is not intended to compete with NumPy or SciPy.

Examples

from statistics import (mean, fmean, median, mode, stdev, pstdev,
                        quantiles, correlation, linear_regression, NormalDist)

data = [1.5, 2.5, 2.5, 2.75, 3.25, 4.75]
mean(data)            # 2.875
fmean(data)           # always a float, faster
median(data)          # 2.625 (mean of middle two)
mode(data)            # 2.5
stdev(data)           # sample standard deviation
pstdev(data)          # population standard deviation
quantiles(data, n=4)  # 3 cut points (quartiles)

x = [1, 2, 3, 4, 5]
y = [2, 4, 5, 4, 5]
correlation(x, y)                      # Pearson's r
slope, intercept = linear_regression(x, y)
NormalDist(mu=100, sigma=15).cdf(130)

Choosing a function

| Function | Returns | |---|---| | mean(data) | the sample arithmetic mean; keeps Fraction and Decimal types | | fmean(data, weights=None) | the mean as a float; runs faster than mean() | | median(data) | the middle value, using the mean of middle two; robust to outliers | | mode(data) | the single most common data point; the first one on ties | | stdev / variance | sample statistics, needing at least two data points | | pstdev / pvariance | population statistics | | quantiles(data, n=4) | n - 1 cut points; n=10 for deciles, n=100 for percentiles |

More

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python docs, statistics - Mathematical statistics functions; python/cpython (GitHub), Lib/statistics.py. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python docs, statistics - Mathematical statistics functions; python/cpython (GitHub), Lib/statistics.py. PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:s1f4h8qt

iinventedlight. 2026. "Python statistics - mean, median, stdev, quantiles and correlation without NumPy." iinventedlight Library, iil:note:s1f4h8qt, version of 2026-11-18. https://iinventedlight.com/library/notes/python-statistics/. License: CC-BY-4.0.

@misc{iil_note_s1f4h8qt,
  author = {{iinventedlight}},
  title = {{Python statistics - mean, median, stdev, quantiles and correlation without NumPy}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/python-statistics/},
  note = {Permanent ID iil:note:s1f4h8qt. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-statistics.md.