statistics.median_high(data)
The statistics.median_high function returns the median of the elements in data. For its calculation, the ordered elements are considered: If the number of elements is odd, the function returns the value that occupies the central position. If the number of elements is even, the highest value of the two closest to the center position is returned.
- data: Sequence or iterable from whose elements you want to calculate the median.
The statistics.median_high function returns an integer or real number.
We can obtain the median of the numbers contained in a list with the following code:
In this case, the number of elements is odd, so the function returns the value that occupies the central position if we consider them ordered (in the example the values are already ordered to make its interpretation easier).
If the number of elements is even, the highest value of the two closest to the central position is returned (the values 3 and 4 in the following example):