mean median mode Disagree By Design

statistics.mean, median, mode, and multimode give four different centers for one skewed list, and the disagreement itself is the signal worth reading.

PythonData Integrity

Code

pythonsnippet
17 lines
from statistics import mean, median, median_low, median_high, mode, multimode
from statistics import variance, stdev

values = [1, 2, 2, 3, 100]

# 均值被极端值拉高;中位数稳健;mode 取最常见值;multimode 返回全部众数
print(mean(values), median(values), mode(values), multimode(values))

# 偶数个元素:median 取两数均值,low/high 各取其一
even = [1, 2, 3, 4]
print(median(even), median_low(even), median_high(even))

# 离散度:方差与标准差(样本口径,除以 n-1)
print(round(variance([1, 2, 3, 4]), 2), round(stdev([1, 2, 3, 4]), 2))

# mode 对单一众数返回标量;multimode 恒返回列表
print(mode([7, 7, 7]), multimode([7, 7, 7]))

Output

Captured from a sandboxed run of this snippet in the build pipeline.

21.6 2 2 [2]
2.5 2 3
1.67 1.29
7 [7]

Inside the snippet

mean, median, median_low, median_high, mode are the only symbols borrowed from statistics — the coupling is explicit and narrow.

Module-level bindings hold the data — values, even — with no function scope in between.

Caveats

  • Nothing to install: statistics ships with the Python standard library.

Interactive Tools for This Topic

FAQ

Does this require external packages?
No. It relies only on built-in language and platform APIs, so you can paste it into a project without installing anything. Every import resolves inside the standard library — `statistics`. Its state lives in module-level bindings: `values`, `even`.