pandas.cut()

pandas.cut

pandas.cut(x, bins, right=True, labels=None, retbins=False, precision=3, include_lowest=False)

Return indices of half-open bins to which each value of x belongs.

Parameters:

x : array-like

Input array to be binned. It has to be 1-dimensional.

bins : int or sequence of scalars

If bins is an int, it defines the number of equal-width bins in the range of x. However, in this case, the range of x is extended by .1% on each side to include the min or max values of x. If bins is a sequence it defines the bin edges allowing for non-uniform bin w