Call Us: US - +1 845 478 5244 | UK - +44 20 7193 7850 | AUS - +61 2 8005 4826

Return the sample arithmetic mean of data

Using the arithmetic mean would give an average of about 5.167, which is too high.

StatisticsError is raised if data is empty, or any element is less than zero.

New in version 3.6.statistics.median(data)

Return the median (middle value) of numeric data, using the common “mean of middle two” method. If datais empty, StatisticsError is raised. data can be a sequence or iterator.

The median is a robust measure of central location, and is less affected by the presence of outliers in your data. When the number of data points is odd, the middle data point is returned:

>>> median([1, 3, 5])

When the number of data points is even, the median is interpolated by taking the average of the two middle values:

>>> median([1, 3, 5, 7])

This is suited for when your data is discrete, and you don’t mind that the median may not be an actual data point.

If your data is ordinal (supports order operations) but not numeric (doesn’t support addition), you should use median_low() or median_high() instead.