pandas.CategoricalIndex.set_categories
pandas 3.1.1 · Index objects · method
Replace the permitted categories. Observations outside the new set can become missing.
Call syntax
CategoricalIndex.set_categories(new_categories, ordered=None, rename=False)Run the example
Edit the example and select Run Python to see the result.
Parameters
| Parameter | Requirement | Accepted 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
CategoricalIndex