Table Of Contents


Enter search terms or a module, class or function name.


CategoricalIndex.rename_categories(*args, **kwargs)[source]

Renames categories.


new_categories : list-like or dict-like

  • list-like: all items must be unique and the number of items in the new categories must match the existing number of categories.
  • dict-like: specifies a mapping from old categories to new. Categories not contained in the mapping are passed through and extra categories in the mapping are ignored. New in version 0.21.0.


Currently, Series are considered list like. In a future version of pandas they’ll be considered dict-like.

inplace : boolean (default: False)

Whether or not to rename the categories inplace or return a copy of this categorical with renamed categories.


cat : Categorical or None

With inplace=False, the new categorical is returned. With inplace=True, there is no return value.



If new categories are list-like and do not have the same number of items than the current categories or do not validate as categories


>>> c = Categorical(['a', 'a', 'b'])
>>> c.rename_categories([0, 1])
[0, 0, 1]
Categories (2, int64): [0, 1]

For dict-like new_categories, extra keys are ignored and categories not in the dictionary are passed through

>>> c.rename_categories({'a': 'A', 'c': 'C'})
[A, A, b]
Categories (2, object): [A, b]
Scroll To Top