Codectionary / Developer documentation / Python

Descriptive Statistics

statistics computes common summaries without an external numerical package. Mean and median describe different aspects of a dataset, especially when outliers are present. Run as a Python 3.11+ script.

Syntax

mean(data); median(data); pstdev(data)

Examples

Descriptive Statistics

Run as a Python 3.11+ script.

from statistics import mean, median, pstdev
samples = [2, 2, 4, 8]
print(mean(samples))
print(median(samples))
print(round(pstdev(samples), 3))
  1. Expected output: 4 3.0 2.449
  2. The mean is 16/4. The median averages the two central values. pstdev treats the supplied values as the entire population.

Best practices

  • Use stdev rather than pstdev when estimating population spread from a sample.
  • Reject or deliberately handle missing values and NaNs before summarizing.

Runtime & versions

Python interpreter. Feature availability depends on the language and runtime version used by your project; consult the official reference below.

Python language reference

Specifications & further reading