In this Python tutorial, we will be using the statistics package of Python to learn the functions. I am running Python IDLE (Python GUI) version 3.7 for statistics in Python. This Python tutorial will discuss the averages and masures of central location with arithmetic mean (“average”) of data, harmonic mean of data, median (middle value) of data, low median of data, high median of data, median, or 50th percentile, of grouped data and mode (most common value) of discrete data. And the measures of spread for population standard deviation of data, population variance of data, sample standard deviation of data, and sample variance of data.

Also, the functions that are covered for the averages are **mean()**, **harmonic_mean()**, **median()**, **median_low()**, **median_high()**, **median_grouped()**, and **mode()**. In addition, the functions for the measure of spread are **pstdev()**, **pvariance()**, **stdev()**, and **variance()**.

## Averages and Measures of Central Location

The below Python statistical functions calculate an average of a typical value from a population and/or sample.

- Arithmetic mean (“average”) of data:
**mean()** - Harmonic mean of data:
**harmonic_mean()** - Median (middle value) of data:
**median()** - Low median of data:
**median_low()** - High median of data:
**median_high()** - Median, or 50th percentile, of grouped data:
**median_grouped()** - Mode (most common value) of discrete data:
**mode()**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import statistics numbers = [100.1, 300.3, 300.3, 400.4, 500.5, 700.7] mean = statistics.mean(numbers) print('Mean of data: ', mean) harmonic_mean = statistics.harmonic_mean(numbers) print('Harmonic mean of data: ', harmonic_mean) median = statistics.median(numbers) print('Median of data : ', median) median_low = statistics.median_low(numbers) print('Low median of data: ', median_low) median_high = statistics.median_high(numbers) print('High median of data: ', median_high) median_grouped = statistics.median_grouped(numbers) print('Median, or 50th percentile, of grouped data: ', median_grouped) mode = statistics.mode(numbers) print('Mode (most common value) of discrete data: ', mode) |

## Measures of Spread

These functions calculate a measure of how much the population or sample tends to deviate from the typical or average values.

- Population standard deviation of data:
**pstdev()** - Population variance of data:
**pvariance()** - Sample standard deviation of data:
**stdev()** - Sample variance of data:
**variance()**

1 2 3 4 5 6 7 8 9 10 11 12 13 | import statistics pstdev = statistics.pstdev(numbers) print('Population standard deviation of data: ', pstdev) pvariance = statistics.pvariance(numbers) print('Population variance of data: ', pvariance) stdev = statistics.stdev(numbers) print('Sample standard deviation of data: ', stdev) variance = statistics.variance(numbers) print('Sample variance of data: ', variance) |

I hope this lesson on statistics in Python was helpful in learning the arithmetic mean (“average”) of data, harmonic mean of data, median (middle value) of data, low median of data, high median of data, median, or 50th percentile, of grouped data and mode (most common value) of discrete data. And the measures of spread for population standard deviation of data, population variance of data, sample standard deviation of data, and sample variance of data.