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

 

In this tutorial, I’ll show how to apply the stdev and pstdev functions in the Python programming language.

Table of contents:

Let’s take a look at some Python codes in action:

 

Creation of Example Data

We’ll use the data below as a basis for this Python programming tutorial.

my_list = [4, 1, 3, 8, 2, 7, 5, 8, 2, 7, 9, 1, 5]  # Create example list
print(my_list)                                     # Print example list
# [4, 1, 3, 8, 2, 7, 5, 8, 2, 7, 9, 1, 5]

As you can see based on the previous output of the Python console, our example data is a list object containing several integer values.

 

Example 1: Get Population Standard Deviation Using pstdev() Function of statistics Module

Example 1 illustrates how to calculate the population standard deviation using the pstdev function of the statistics module.

For the examples of this tutorial, we’ll first have to load the statistics module:

import statistics                                  # Import statistics

Next, we can apply the statistics.pstdev function to our example list as shown below:

print(statistics.pstdev(my_list))                  # Apply pstdev() function
# 2.7218163096852512

As you can see, the population standard deviation of our example list is 2.72.

 

Example 2: Get Sample Standard Deviation Using stdev() Function of statistics Module

In this example, I’ll demonstrate how to find and get the sample standard deviation of a list using the statistics module.

For this task, we can apply the stdev function (note the missing p at the beginning of the function name) to our list:

print(statistics.stdev(my_list))                   # Apply stdev() function
# 2.8329562343320847

The sample standard deviation is slightly higher than the population standard deviation that we have computed in Example 1.

 

Video & Further Resources

Do you need more information on the Python syntax of this tutorial? Then I recommend having a look at the following video which I have published on my YouTube channel. I illustrate the contents of this article in the video.

 

The YouTube video will be added soon.

 

In addition, you may want to read the other articles on my homepage.

 

Summary: At this point you should have learned how to apply the stdev and pstdev functions of the statistics module in the Python programming language. If you have any further questions, please let me know in the comments section.

 

Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.


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.

Top