cudf.core.column.categorical.CategoricalAccessor.reorder_categories#
- CategoricalAccessor.reorder_categories(new_categories: Any, ordered: bool = False) SeriesOrIndex | None #
Reorder categories as specified in new_categories.
new_categories need to include all old categories and no new category items.
- Parameters:
- new_categoriesIndex-like
The categories in new order.
- orderedbool, optional
Whether or not the categorical is treated as a ordered categorical. If not given, do not change the ordered information.
- Returns:
- cat
Categorical with reordered categories
- Raises:
- ValueError
If the new categories do not contain all old category items or any new ones.
Examples
>>> import cudf >>> s = cudf.Series([10, 1, 1, 2, 10, 2, 10], dtype="category") >>> s 0 10 1 1 2 1 3 2 4 10 5 2 6 10 dtype: category Categories (3, int64): [1, 2, 10] >>> s.cat.reorder_categories([10, 1, 2]) 0 10 1 1 2 1 3 2 4 10 5 2 6 10 dtype: category Categories (3, int64): [10, 1, 2] >>> s.cat.reorder_categories([10, 1]) ValueError: items in new_categories are not the same as in old categories