Movatterモバイル変換


[0]ホーム

URL:


Python Tutorial

Python statistics.median_grouped()Function



The Pythonstatistics.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.
  • L: The lower limit.
  • interval: The interval width.
  • N: The total number of data points.
  • CF: The number of data points below the median interval.
  • F: The number of data points in the median interval.

Syntax

Following is the basic syntax of thestatistics.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 Value

This function returns the median of the grouped continuous data.

Example 1

In the below example, we are calculating the median of grouped continuous data usingstatistics.median_grouped() function −

import statisticsx = statistics.median_grouped([1, 3, 7, 9])print(x)

Output

This produces the following result −

6.5

Example 2

The following example calculates the median of the grouped continuous data usingstatistics.median_grouped() function −

import statisticsx = statistics.median_grouped([2, 5, 7, 9], 5)print(x)

Output

The output obtained is as follows −

4.5

Example 3

Now, we are calculating the median for the float values usingstatistics.median_grouped() function.

import statisticsx = 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
Print Page
Advertisements

[8]ページ先頭

©2009-2025 Movatter.jp