Python - Statistics Module
The statistics module provides functions to mathematical statistics of numeric data. The following popular statistical functions are defined in this module.
Mean
The mean()
method calculates the arithmetic mean of the numbers in a list.
Example:
>>> import statistics
>>> statistics.mean([2,5,6,9])
5.5
Median
The median()
method returns the middle value of numeric data in a list.
Example:
>>> import statistics
>>> statistics.median([1,2,3,8,9])
3
>>> statistics.median([1,2,3,7,8,9])
5.0
Mode
The mode()
method returns the most common data point in the list.
Example:
>>> import statistics
>>> statistics.mode([2,5,3,2,8,3,9,4,2,5,6])
2
Standard Deviation
The stdev()
method calculates the standard deviation on a given sample in the form of a list.
Example:
>>> import statistics
>>> statistics.stdev([1,1.5,2,2.5,3,3.5,4,4.5,5])
1.3693063937629153
Learn about the statistics module in Python docs.