The Python statistics.median_grouped() calculates the median of grouped data, as the 50th percentile.
This function considers data points as continuous data and calculates the 50% median by using a specified interval width (default value = 1).
The mathematical formula for Grouped Median is −
GMedian = L + interval * (N/2-CF)/F.
Following is the basic syntax of the statistics.median_grouped() function −
statistics.median_grouped(data, interval)Parameters
Here, the data values can be used as any sequence, list or iterator. When it comes to intervals, the default value is 1.
Return ValueThis function returns the median of the grouped continuous data.
Example 1In the below example, we are calculating the median of grouped continuous data using statistics.median_grouped() function −
import statistics x = statistics.median_grouped([1, 3, 7, 9]) print(x)Output
This produces the following result −
6.5Example 2
The following example calculates the median of the grouped continuous data using statistics.median_grouped() function −
import statistics x = statistics.median_grouped([2, 5, 7, 9], 5) print(x)Output
The output obtained is as follows −
4.5Example 3
Now, we are calculating the median for the float values using statistics.median_grouped() function.
import statistics x = statistics.median_grouped([3.2, 5.6, 0.7, 1.9], 2.5) print(x)Output
This result is produced as follows −
1.9500000000000002
python_modules.htm
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4