Median is often referred to as the robust measure of central location and is less affected by the presence of outliers in data.
statistics module in Python allows three options to deal with median / middle elements in a data set, which are
median(), median_low() and median_high().
The high median is always a member of the data set. When the number of data points is odd, the middle value is returned. When it is even, the larger of the two middle values is returned. Let’s see how
median_high() function works.
Syntax :median_high( [data – set] )
[data-set] : Takes in a list, or an interable set of numeric data.
Returntype :Returns the high median of the numeric data (always in actual data-set).
Exceptions :StatisticsError is raised when data-set is empty.
Code #1 : Working
High median of the data-set is 4
Code #2 : Working of median_high() and median() to demonstrate the difference between them.
Median of the set is 3.5 High Median of the set is 4
Code #3 : Working of median_high() on a varying range of data-values.
High Median of data-set 1 is 5 High Median of data-set 2 is 6.7 High Median of data-set 3 is 10/3 High Median of data-set 4 is -5 High Median of data-set 5 is 1
Code #4 : Demonstration of StatisticsError
Traceback (most recent call last): File "/home/fc2eae1616bfaa0987b261d9d40f4602.py", line 10, in print(median_high(empty)) File "/usr/lib/python3.5/statistics.py", line 398, in median_high raise StatisticsError("no median for empty data") statistics.StatisticsError: no median for empty data
The high median is used only when the data is discrete and the prefer the median to be an actual median rather than an interpolated set of data.
- Python statistics | median()
- Python statistics | stdev()
- Python statistics | median_grouped()
- Python statistics | mean() function
- Python statistics | pvariance()
- Python – 68-95-99.7 rule in Statistics
- Python statistics | variance()
- Python statistics | harmonic_mean()
- Python statistics | median_low()
- Python - Laplace Distribution in Statistics
- Python - kappa3 Distribution in Statistics
- Python - Von Mises Distribution in Statistics
- Python - Wald Distribution in Statistics
- Python - kappa4 Distribution in Statistics
- Python - Johnson SU Distribution in Statistics
- Python - Bernoulli Distribution in Statistics
- Python - Boltzmann Distribution in Statistics
- Python - ksone Distribution in Statistics
- Python - Levy Distribution in Statistics
- Python - Student’s t Distribution in Statistics
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.