The statistics.pstdev()
method in Python returns the population standard deviation. This method is unlike the statistics.stdev()
method, which only calculates the standard deviation from a sample of data, and instead calculates the standard deviation of an entire population.
Standard deviation is simply the square root of variance or the sample variance and is found by:
standard deviation = √variance
statistics.pstdev(data, xbar)
Parameter | Function |
| This is a required argument. It is the data to be used. It can be a list, a sequence, or an iterator. |
| This is an optional argument. It is the mean of the data provided. If the value is not provided, by default, Python calculates the mean of the data. |
The statistics.pstdev()
method returns a float value, which represents the population standard deviation of a given data.
Let’s use the statistics.pstdev()
method to calculate the population standard deviation for the given data.
import statistics# creating a data setdata = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]# to obtain the population standard deviationp_standard_deviation = statistics.pstdev(data)print('The population standard deviation is', p_standard_deviation)
statistics
module.data
.statistics.pstdev()
method to obtain the population standard deviation of the data
variable and assigned the value to another variable, p_standard_deviation
.p_standard_deviation
, which contains the population standard deviation of the given data.