Python 3.4+statisticsfunction
statistics.pstdev
spread
Population standard deviation (with n degrees of freedom).
Syntax
statistics.pstdev(data)
The p stands for population: the divisor is n. If your numbers are only a sample drawn from something larger, you want stdev with its n-1 correction, otherwise the spread comes out systematically too small; pstdev is honest only when the data is the whole population. The mu argument is not an arbitrary reference point but a mean you already know to be true — feed it anything else and you get the root mean square deviation about that point, not a standard deviation.
Examples
import statistics
print(statistics.pstdev([2, 4, 4, 4, 5, 5, 7, 9])) # → 2.0
print(statistics.pstdev([2, 4, 4, 4, 5, 5, 7, 9], mu=5)) # → 2.0
print(statistics.pstdev([1, 2, 3, 4, 5])) # → 1.4142135623730951
print(statistics.pstdev([5])) # → 0.0
print(statistics.stdev([2, 4, 4, 4, 5, 5, 7, 9])) # → 2.138089935299395
See also
Open in the full glossarydocs.python.orgReport an inaccuracy