stats.binned_statistic (x, values, statistic = & # 39; mean & # 39 ;, bins = 10, range = None)
calculates statistic value for given data (array elements).
It works similarly to the mean -median-mode-in-python-without-libraries/">median, count, or other statistics of values for each bin.
Parameters:
arr: [array_like] input array to be binned.
values: [array_like] on which stats to be calculated.
statistics: Statistics to compute { mean , count, mean -median-mode-in-python-without-libraries/">median, sum, function}. Default is mean .
bin: [int or scalars] If bins is an int, it defines the number of equal-width bins in the given range (10, by default). If bins is a sequence, it defines the bin edges.
range: (float, float) Lower and upper range of the bins and if not provided, range is from x.max () to x.min ().Results: Statistics value for each bin; bin edges; bin number.
Code # 1:
|
Output:
arr: [20, 2, 7, 1, 34] binned_statistic for mean -median-mode-in-python-without-libraries/">median: BinnedStatisticResult (statistic = array ([2., nan, 0., 4.]), bin_edges = array ([1 ., 9.25, 17.5, 25.75, 34.]), binnumber = arr ay ([3, 1, 1, 1, 4], dtype = int64))
Code # 2:
|
Output:
binned_statistic for mean : BinnedStatisticResult (statistic = array ([2., 2.]), bin_edges = array ([1., 17.5, 34.]), binnumber = array ([2, 1, 1, 1, 2], dtype = int64))