Python Glossary Русский

Python 3.4+statisticsfunction

statistics.median_low

median

Low median: for even-length data returns the smaller of the two middle values.

Syntax

statistics.median_low(data)

The point of median_low is that it never invents a value: plain median averages the two middle items on even-length data and can return something absent from the sample (2.5 for [1, 2, 3, 4]), while median_low hands back an actual data point — exactly what ordinal data that cannot be averaged needs. You do not have to pre-sort the input, it sorts internally, and empty data raises StatisticsError rather than returning None.

Examples

import statistics
print(statistics.median_low([1, 2, 3, 4]))   # → 2
print(statistics.median_low([1, 3, 5]))      # → 3
print(statistics.median_low([5, 1, 4, 2]))   # → 2
print(statistics.median_low(['a', 'b', 'c', 'd']))   # → b
print(statistics.median([1, 2, 3, 4]), statistics.median_low([1, 2, 3, 4]))   # → 2.5 2
print(statistics.median_low([]))             # → StatisticsError

See also

Open in the full glossarydocs.python.orgReport an inaccuracy