pandas.Series.cat.set_categories

pandas 3.1.1 · Series and accessors · method

Replace the permitted categories. Observations outside the new set can become missing.

Call syntax

Series.cat.set_categories(new_categories, ordered=None, rename=False)

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.

rename Optional
Positional or keyword
Default False
bool

Returns

Categorical