Articles

# Python Statistics Module - mean | median | mode | stdev | variance

In this python statistics module we will discuss the methods that are available in this module.

Introduction

Statistics are used to perform data analysis and use to interpret the data within less time.

We will see the methods that is supported by this module.

Method 1 : mean()

mean is used to return the average value of the given data.

Syntax:

``statistics.mean(my_data)``

where, my_data refers to the list that contain integer elements.

Example:

In this example, we will get the mean from the list that contains 10 elements

``````#importing the statistics module
import statistics

#consider the data that contains 10 integers
my_list=[23,45,67,54,33,6,7,8,9,32]

#display the data
print(my_list)

print()

#find the mean
print(statistics.mean(my_list))``````

Output:

From the above code, the mean for 10 elements in the list is returned.

``````[23, 45, 67, 54, 33, 6, 7, 8, 9, 32]

28.4``````

Method 2 : median()

median is used to return the median of the given data.

Syntax:

``statistics.median(my_data)``

where, my_data refers to the list that contain integer elements.

Example:

In this example, we will get the median from the list that contains 10 elements

``````#importing the statistics module
import statistics

#consider the data that contains 10 integers
my_list=[23,45,67,54,33,6,7,8,9,32]

#display the data
print(my_list)

print()

#find the median
print(statistics.median(my_list))``````

Output:

From the above code, the median for 10 elements in the list is returned.

``````[23, 45, 67, 54, 33, 6, 7, 8, 9, 32]

27.5``````

Method 3 : mode()

mode is used to return the most repeated value of the given data.

Syntax:

``statistics.mode(my_data)``

where, my_data refers to the list that contain integer elements.

Example:

In this example, we will get the mode from the list that contains 10 elements

``````#importing the statistics module
import statistics

#consider the data that contains 10 integers
my_list=[23,45,67,54,33,6,7,8,23,32]

#display the data
print(my_list)

print()

#find the mode
print(statistics.mode(my_list))``````

Output:

From the above code, the mode for 10 elements in the list is returned.

``````[23, 45, 67, 54, 33, 6, 7, 8, 9, 32]

23``````

Method 4 : stdev()

stdev is used to return the standard deviation from the given data.

Syntax:

``statistics.stdev(my_data)``

where, my_data refers to the list that contain integer elements.

Example:

In this example, we will get the standard deviation from the list that contains 10 elements.

``````#importing the statistics module
import statistics

#consider the data that contains 10 integers
my_list=[23,45,67,54,33,6,7,8,23,32]

#display the data
print(my_list)

print()

#find the standard deviation
print(statistics.stdev(my_list))``````

Output:

From the above code, the standard deviation for 10 elements in the list is returned..

``````[23, 45, 67, 54, 33, 6, 7, 8, 23, 32]

20.735369674919124``````

Method 5 : variance()

variance is used to return the variance  from the given data.

Syntax:

``statistics.variance(my_data)``

where, my_data refers to the list that contain integer elements.

Example:

In this example, we will get the variance  from the list that contains 10 elements.

``````#importing the statistics module
import statistics

#consider the data that contains 10 integers
my_list=[23,45,67,54,33,6,7,8,23,32]

#display the data
print(my_list)

print()

#find the standard deviation
print(statistics.stdev(my_list))``````

Output:

From the above code, the variance for 10 elements in the list is returned...

``````[23, 45, 67, 54, 33, 6, 7, 8, 23, 32]

429.9555555555556``````

This is all about python statistics module.

Python Numbers Program

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com