Applying variance & pvariance Functions of statistics Module in Python (2 Examples)

In this Python tutorial you’ll learn how to apply the pvariance and variance functions of the statistics module.

Creation of Example Data

x = [1, 3, 3, 7, 1, 3, 5, 1, 2, 2, 1, 2, 1, 3, 1, 7]  # Constructing a list in Python
print(x)                                              # Displaying the example list
# [1, 3, 3, 7, 1, 3, 5, 1, 2, 2, 1, 2, 1, 3, 1, 7]

Example 1: How to Apply the variance() Function of the statistics Module to Calculate the Sample Variance

import statistics                                     # Load statistics
print(statistics.variance(x))                         # Sample Variance
# 4.095833333333333

Example 2: How to Apply the pvariance() Function of the statistics Module to Calculate the Population Variance

print(statistics.pvariance(x))                        # Population Variance
# 3.83984375

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top