The statistics.pvariance()
method in Python is used to return the population variance of a given data.
This method is unlike the statistics.variance()
method, which calculates the variance of a sample of data. Instead, the statistics.pvariance()
method calculates the variance of an entire population.
Variance is the sum of the squared distances of each term distributed from the mean of the data divided by the number of observations. It is given by:
statistics.pvariance(data, xbar)
Parameter | Value |
| This is required. It is the data to be used. It can be a list, a sequence, or iterator |
| This is optional. It is the mean of the data provided. If the value is not provided Python calculates the mean of the data by default. |
statistics.pvariance()
method returns a float value that represents the population variance of a given data.
Let’s use the statistics.pvariance()
method to calculate the population variance for a given data.
import statistics# creating a data setdata = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]# to obtain the variancethe_pvariance = statistics.pvariance(data)print('The population variance is', the_pvariance)
statistics
module.data
.statistics.pvariance()
method to obtain the population variance of the data
and assign the value to another variable the_pvariance
.the_pvariance
, which contains the population variance of the given data.