pandas.qcut

pandas 3.1.1 · General functions · function

Make bins based on quantiles so bins have approximately equal numbers of observations.

Call syntax

pd.qcut(x, q, labels=None, retbins=False, precision=3, duplicates='raise')

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.

q Required
Positional or keyword
int or list-like of float

Provide quantiles as fractions between 0 and 1, or a number of quantile bins for qcut.

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.

duplicates Optional
Positional or keyword
Default 'raise'
{default 'raise', 'drop'}

Choose what happens when duplicate bin boundaries occur.

Returns

out · Categorical or Series or array of integers if labels is False; bins · ndarray of floats