How to Find or Calculate Grouped Median in Python using median_grouped() Function

median_grouped() function exists in Standard statistics Library of Python Programming Language. The basic purpose of this function is to calculate the median of given continuous grouped numeric data. The given data will always be in the form of sequence or iterator.

Median is used to locate the central tendency of grouped numeric data.

Syntax of median_grouped() Function in Python

The syntax of median_grouped() function in Python is as follows:
statistics.mean_grouped(data, interval = n)


Parameters of median_grouped() Function in Python

data – This parameter can be any sequence or iterator (lists, tuples)
interval – This parameter represents the class interval. By default, a class interval is 1. But we can use any class interval n where n is an integer.Note: If data is empty, median_grouped() function raises a StatisticsError


Return Value of median_grouped() in Python

Return value of median_grouped() is a floating point number after calculating median of given data in iterator (lists, tuples)


median_grouped() Function Examples in Python

# import statistics library
import statistics


print(statistics.median_grouped([3,9,12,15,17], 1))

print(statistics.median_grouped([3,9,12,15,17], 2))

Output of median_grouped() Function in Python