Statistical functions in Python

The Python standard library module "statistics", offers statistical functions that return the measures of central tendency and measures of dispersion

Statistics Updated 12 Jan 2017 2 min read

Even the simple most data analysis requires application of statistical functions

such as finding the mean value of a collection of data.

Python standard library has several statistical functions built-in with it.

The statistical functions are available to the programmer through the python module statistics, which can be imported as given here.

python
import statistics

The module statistics provides two types of functions.

  • A set of functions to find where the data is centered around in a distribution - i.e, Functions to find the measures of central tendencies. e.g., Mean(), Median(), Mode

  • A set of functions to find how the data is dispersed, meaning how the data is dispersed from the central values. e.g., pvariance(), pstdev() which find the variance and the standard deviation of the distribution.

List of statistical functions to find the measures of central tendency

mean()Finds and returns the Arithmetic Mean of the data, popularly called as the average value of the data.
harmonic_mean()Returns the harmonic mean also called as the subcontrary mean of the data
median()Returns the median value, which is the middle value of the distribution.
median_low()Returns the low median value of the distribution
median_high()Returns the high median of the distribution
median_grouped()Median of the grouped data will be returned.
mode()Returns the most occurring value of the distribution, which is called as the mode of the distribution.

List of statistical functions to find the measures of dispersion

pstdevReturns the standard deviation of the population data
stdevReturns the standard deviation the sample data
pvarianceReturns the variance of the population data
varianceReturns the variance of the sample data