Python statistics.pvariance() Method
Python statistics.pvariance()Used to calculate the sample variance of a given dataset.
Syntax
The syntax of the statistics.pvariance() method is as follows:
statistics.pvariance(data, mu=None)
Parameter description:
- data-- An iterable containing numeric values, such as a list or tuple.
- mu-- Optional parameter, representing the mean of the dataset. If not provided, the function calculates the mean of the dataset internally.
Return Value
The function calculates and returns the sample variance of the given dataset as the result.
Example
The following example demonstrates the pvariance() function:
Example
data = [1, 2, 3, 4, 5]
variance = statistics.pvariance(data)
print(variance)
Output:
2.5
In the above example, the given dataset is [1, 2, 3, 4, 5], and the sample variance calculated using the pvariance() method is 2.5.
Sample variance is a statistic that measures the dispersion of a dataset, representing the average of the squared deviations of data values from the mean. It describes the degree of variability in the data.
Similar to the pstdev() method, the pvariance() method calculates the sample variance rather than the population variance, so it uses an unbiased estimate. If you have data for the entire population, you can usevariance()method to calculate the population variance.
Other extensions
Python statistics module