pandas.cut

pandas 3.1.1 · General functions · function

Assign numeric values to specified intervals or to a fixed number of equal-width bins.

Call syntax

pd.cut(…) Full signature
pd.cut(
    x,
    bins,
    right=True,
    labels=None,
    retbins=False,
    precision=3,
    include_lowest=False,
    duplicates='raise',
    ordered=True,
)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
x Required
Positional or keyword
1d ndarray or Series

Choose the column or positional input mapped to the horizontal axis.

bins Required
Positional or keyword
int, sequence of scalars, or IntervalIndex

Set a number of bins or provide bin boundaries.

right Optional
Positional or keyword
Default True
bool

Supply the right-hand input or the right endpoint of the interval.

labels Optional
Positional or keyword
Default None
array or False

Provide the labels used for selecting rows, renaming entries, or naming bins.

retbins Optional
Positional or keyword
Default False
bool

Return the computed bin boundaries along with the binned result.

precision Optional
Positional or keyword
Default 3
int

Choose the requested number of decimal places or displayed digits.

include_lowest Optional
Positional or keyword
Default False
bool
duplicates Optional
Positional or keyword
Default 'raise'
{'raise', 'drop'}

Choose what happens when duplicate bin boundaries occur.

ordered Optional
Positional or keyword
Default True
bool

Choose whether the category sequence defines an ordering.

Returns

out · Categorical, Series, or ndarray; bins · numpy.ndarray or IntervalIndex.