Applying stdev & pstdev Functions of statistics Module in Python (2 Examples)

This post illustrates how to apply the stdev and pstdev functions in the Python programming language.

Creation of Exemplifying 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 stdev() Function of the statistics Module to Calculate the Sample Standard Deviation

import statistics                                     # Load statistics
print(statistics.stdev(x))                            # Sample Standard Deviation
# 2.023816526598529

Example 2: How to Apply the pstdev() Function of the statistics Module to Calculate the Population Standard Deviation

print(statistics.pstdev(x))                           # Population Standard Deviation
# 1.9595519258238603

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