The statistics module in Python allows you to use three options for working with median / average elements in a dataset, namely median (), median_low () and median_high ()
.
Low Median is always a member of the dataset. If the number of data points is odd, the average is returned. When it is even, the lower of the two means is returned. Let`s see how median_low()
works.
Syntax:
median_low ( [dataset] )
Parameters:
[dataset] : 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 dataset.
Exceptions:
StatisticsError is raised when dataset is empty .
Code # 1: Operation

Output:
Low median of the dataset is 3
Code # 2: Working with median_low () and median to differentiate between them.
Output:
Median of the set is 3.5 Low Median of the set is 3
Code # 3: How median_low () works with different data ranges


Output:
Low Median of dataset 1 is 5 Low Median of dataset 2 is 5.1 Low Median of dataset 3 is 2/3 Low Median of dataset 4 is 5 Low Median of dataset 5 is 1
Code # 4: Increased statistical error
# Code Python for demonstration
# StatisticsError of median_low ()
# module import statistics
from
statistics
import median_low
# create an empty set data
empty
=
[]
# will raise StatisticsError
print
(median_low (empty))
Output:
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 dataApplications:
media n_low () is used when the data is discrete and would prefer the median to be an actual point in the data rather than extrapolated.