CategoricalIndex.rename_categories(*args, **kwargs) [source]
Renames categories.
| Parameters: |
new_categories : list-like, dict-like or callable
Warning 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. |
|---|---|
| Returns: |
cat : Categorical or None With |
| Raises: |
ValueError 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 |
See also
reorder_categories, add_categories, remove_categories, remove_unused_categories, set_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]
You may also provide a callable to create the new categories
>>> c.rename_categories(lambda x: x.upper()) [A, A, B] Categories (2, object): [A, B]
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
http://pandas.pydata.org/pandas-docs/version/0.23.4/generated/pandas.CategoricalIndex.rename_categories.html