Median is often referred to as the robust measure of the 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 low 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 smaller of the two middle values is returned. Let’s see how
Syntax :median_low( [data-set] )
[data-set] : Takes in a list, tuple or an interable set of numeric data.
Returntype :Returns the low median of numeric data. Low median is a member of actual data-set.
Exceptions :StatisticsError is raised when data-set is empty.
Code #1 : Working
Low median of the data-set is 3
Code #2 : Working of median_low() and median to distinguish between them.
Median of the set is 3.5 Low Median of the set is 3
Code #3 : Working of median_low() on a varying range of data-set
Low Median of data-set 1 is 5 Low Median of data-set 2 is 5.1 Low Median of data-set 3 is 2/3 Low Median of data-set 4 is -5 Low Median of data-set 5 is -1
Code #4 : Raising StatisticsError
Traceback (most recent call last): File "/home/5f3e758236f872d014f9d741743c30a4.py", line 10, in print(median_low(empty)) File "/usr/lib/python3.5/statistics.py", line 376, in median_low raise StatisticsError("no median for empty data") statistics.StatisticsError: no median for empty data
median_low() is used when the data is discrete and prefer median to be actual point in data rather than an extrapolated one.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- mode() function in Python statistics module
- median_grouped() function in Python statistics module
- median_high() function in Python statistics module
- median() function in Python statistics module
- stdev() method in Python statistics module
- Python statistics | mean() function
- Python - Power-Function Distribution in Statistics
- fmean() function in Python statistics
- Python statistics | pvariance()
- Use Pandas to Calculate Statistics in Python
- Python statistics | variance()
- Python - Moyal Distribution in Statistics
- Python - Maxwell Distribution in Statistics
- Python - Lomax Distribution in Statistics
- Python - Log Normal Distribution in Statistics
- Python - Log Laplace Distribution in Statistics
- Python - Logistic Distribution in Statistics
- Python - Log Gamma Distribution in Statistics
- Python - Levy_stable Distribution in Statistics
- Python - Left-skewed Levy 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 email@example.com. 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.