pandas.Categorical.reorder_categories

pandas 3.1.1 · Arrays, scalars, and data types · method

Set the order of existing categories without changing which category each value belongs to.

Call syntax

Categorical.reorder_categories(new_categories, ordered=None)

Run the example

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

Parameters

ParameterRequirementAccepted values and behavior
new_categories Required
Positional or keyword
Index-like

Provide the category labels to add, assign, or reorder.

ordered Optional
Positional or keyword
Default None
bool

Choose whether the category sequence defines an ordering.

Returns

Categorical