Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

Pandas Series: cat.rename_categories() function

Series-cat.rename_categories() function

The rename_categories() function is used to rename categories.

Syntax:

Series.cat.rename_categories(self, *args, **kwargs)

Parameters:

Name Description Type/Default Value Required / Optional
new_categories
  • 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.
  • callable : a callable that is called on all items in the old categories and whose return values comprise the new categories.
list-like, dict-like or callable Required
inplace Whether or not to rename the categories inplace or return a copy of this categorical with renamed categories. bool, default False Required

Returns: cat : Categorical or None

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

Example:


Download the Pandas Series Notebooks from here.

Previous: Series-str.get_dummies() function
Next: Series-plot.area() function