Python statistics.pvariance() Method
Python statistics.pvariance() Used to compute the sample variance of a given data set.
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 -- an optional parameter indicating the mean of the data set; if not provided, the function computes the mean internally.
Return Value
The function computes and returns the sample variance from the given data set as the result.
Example
The following example demonstrates the pvariance() function:
Example
import
statistics
data
=
[
1
,
2
,
3
,
4
,
5
]
variance
=
statistics.
pvariance
(
data
)
(
variance
)
Output result:
2.5
In the above example, the given data set is [1, 2, 3, 4, 5], and the pvariance() method computes a sample variance of 2.5.
The sample variance is a statistic measuring the dispersion of a data set; it is the average of the squared deviations of data values from the mean. It describes the degree of variability in the data.
Like the pstdev() method, the pvariance() method computes the sample variance rather than the population variance, so it uses an unbiased estimate. If you have data for the entire population, you can use the variance() method to compute the population variance.
Python statistics Module