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))- Expected output: 4 3.0 2.449
- 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