Python statistics.median_grouped() Method
Python statistics.median_grouped() Used to compute the grouped median of a given grouped data set.
Syntax
The syntax of the statistics.median_grouped() method is as follows:
statistics.median_grouped(data, interval=1)
Parameter Description:
- data -- an iterable containing grouped data, such as a list or tuple.
- interval -- an optional parameter indicating the interval width of the grouped data, defaults to 1.
Return Value
The function computes and returns the grouped median from the given grouped data set as the result.
Example
The following example demonstrates the median_grouped() function:
Example
import
statistics
data
=
[
10
,
20
,
30
,
40
]
interval
=
10
median
=
statistics.
median_grouped
(
data
,
interval
)
(
median
)
Output result:
25.0
In the above example, the given grouped data set is [10, 20, 30, 40], with each data point having an interval width of 10. The median_grouped() method computes a grouped median of 25.0.
The median_grouped() method is used for large data sets where data is grouped into continuous intervals rather than listing every data point. It estimates the median of the entire data set by computing the middle value of the grouped data.
Python statistics Module