In python, the statistics module has different functions to perform the mathematical statistics of numeric data.
Following is the example of importing a built-in statistics module to calculate the mathematical statistics of numeric data.
If you observe the above example, we imported statistics
module using import
keyword and used mean()
method to calculate the arithmetic mean (average) of the numbers in the list.
The above statistics module example will return the result as shown below.
Like the mean() method, the statistics module has different methods to calculate mathematical statistics of numeric data.
The statistics module median() method is useful to calculate the median (middle) value of the numeric data in the list.
Following is the example of using the statistics module median() method in python.
The above statistics module median() method example will return the middle value of numeric data in the list as shown below.
The statistics module mode() method is useful to return the most common data point on the list.
Following is an example of using the mode() function to get the common data point from the python list.
The above statistics module mode() function example will return the most common data points from the list as shown below.
The statistics module stdev() method is useful to calculate the standard deviation of the given data.
Following is an example of the statistics module stdev() method to calculate python's sample data's standard deviation.
The above statistics module example will return the result as shown below.
The statistics module variance() method is useful to calculate the variance from a given sample data.
Following is an example of the statistics module variance() method to calculate the variance from python's sample data.
The above statistics module example will return the result as shown below.
The following table lists the different statistics module methods to calculate the mathematical statistics of numeric data based on our requirements.
Method | Description |
---|---|
mean() | It will calculate the arithmetic mean (average) of the numbers in the list. |
harmonic_mean() | It will calculate the harmonic mean (central location) of the numbers in the list. |
median() | It will calculate the median (middle) value of the numeric data in the list. |
median_high() | It will calculate the high median value of the numeric data in the list. |
median_low() | It will calculate the low median value of the numeric data in the list. |
median_grouped() | It will calculate the median of grouped continuous numeric data in the list. |
mode() | It will return the most common data point in the list. |
stdev() | It will calculate the standard deviation of the given data. |
pstdev() | It will calculate the standard deviation from an entire population. |
variance() | It will calculate the variance from a given sample data. |
pvariance() | It will calculate the variance of an entire population. |