Standard deviation is a measure of the amount of variation or dispersion of a set of values around its mean. In Python, we can use the statistics
module to easily calculate the standard deviation of a list of values. Here's an example code:
main.py335 chars15 lines
In the example code above, we first import the statistics
module. We then create a list of numbers data
. We use pstdev()
to calculate the population standard deviation and stdev()
to calculate the sample standard deviation.
Note that pstdev()
calculates the population standard deviation, which assumes that the given data represents the entire population, while stdev()
calculates the sample standard deviation, which assumes that the given data is a random sample from a larger population.
gistlibby LogSnag