mean() Function of statistics Module in Python (Example)

 

In this Python programming tutorial you’ll learn how to apply the statistics.mean function.

The post looks as follows:

Let’s start right away!

 

Creation of Example Data

First, let’s create some example data.

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

The previous output of the Python console shows the structure of our example data: We have constructed a list object containing nine integer values.

 

Example: Apply mean() Function of statistics Module to List

The Python programming code below illustrates how to apply the mean function of the statistics module to get the average of a list of values.

If we want to use the functions of the statistics library, we also have to load statistics:

import statistics           # Import statistics

In the next step, we can apply the mean function of the statistics module to return the arithmetic mean of our data:

print(statistics.mean(my_list))          # Apply statistics.mean function
# 4.888888888888889

As you can see, the mean of our data is 4.889.

 

Video, Further Resources & Summary

Do you need further explanations on the Python code of this article? Then you might have a look at the following video on my YouTube channel. In the video, I show the Python programming codes of this tutorial:

 

 

Besides the video, you may read the related posts that I have published on this website:

 

In this tutorial, I have illustrated how to use the statistics.mean function to compute and find the arithmetic mean in Python. If you have further questions, don’t hesitate to let me know in the comments.

 

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