Python Statistics Module Overview
Explore the Python statistics module, which offers various functions for performing mathematical statistics on numeric data. Learn about key functions available in the module for analyzing and summarizing data.
Python - Statistics Module
The statistics module in Python provides functions for performing mathematical statistics on numeric data. Here are some of its key functions:
Mean
The mean() method calculates the arithmetic mean of the numbers in a list.
Example: Mean
import statistics
print(statistics.mean([2, 5, 6, 9])) # Output: 5.5
Output
5.5
Median
The median() method returns the middle value of numeric data in a list.
Example: Median
import statistics
print(statistics.median([1, 2, 3, 8, 9])) # Output: 3
print(statistics.median([1, 2, 3, 7, 8, 9])) # Output: 5.0
Output
3
5.0
Mode
The mode() method returns the most common data point in the list.
Example: Mode
import statistics
print(statistics.mode([2, 5, 3, 2, 8, 3, 9, 4, 2, 5, 6])) # Output: 2
Output
2
Standard Deviation
The stdev() method calculates the standard deviation on a given sample in the form of a list.
Example: Standard Deviation
import statistics
print(statistics.stdev([1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5])) # Output: 1.3693063937629153
Output
1.3693063937629153