Python statistics.median_high() Method

Python statistics 模块Python statistics Module

Python statistics.median_high()Used to calculate the high median of a given data set.

Syntax

The syntax of the statistics.median_high() method is as follows:

statistics.median_high(data)

Parameter description:

  • data-- An iterable containing numeric values, such as a list or tuple.

Return Value

The function calculates and returns the high median of the data set as the result.

Example

The following example demonstrates the use of the median_high() function:

Example

import statistics

data = [1, 3, 5, 7, 9]
median = statistics.median_high(data)
print(median)

Output result:

5

In the above example, the given data set is [1, 3, 5, 7, 9], and the high median calculated using the median_high() method is 5.

The high median is a method for calculating the median of a data set. It selects the middle value or the larger one after sorting as the median. When the number of elements in the data set is odd, the high median is the same as the ordinary median; when the number of elements is even, the high median selects the larger value.

The median_high() method may be more suitable in some cases, especially when you want to select the larger value as the median. If you want to select the smaller value as the median, you can usemedian_low()method.

Python statistics 模块Python statistics Module

Other extensions