pandas.Series.cat.reorder_categories

Series.cat.reorder_categories(*args, **kwargs)[source]

Reorder categories as specified in new_categories.

new_categories need to include all old categories and no new category items.

Parameters
new_categories:Index-like

The categories in new order.

ordered:bool, optional

Whether or not the categorical is treated as a ordered categorical. If not given, do not change the ordered information.

inplace:bool, default False

Whether or not to reorder the categories inplace or return a copy of this categorical with reordered categories.

Deprecated since version 1.3.0.

Returns
cat:Categorical or None

Categorical with removed categories or None if inplace=True.

Raises
ValueError

If the new categories do not contain all old category items or any new ones

See also

rename_categories

Rename categories.

add_categories

Add new categories.

remove_categories

Remove the specified categories.

remove_unused_categories

Remove categories which are not used.

set_categories

Set the categories to the specified ones.

© 2008–2021, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/1.3.4/reference/api/pandas.Series.cat.reorder_categories.html