cat.
reorder_categories
Reorder categories as specified in new_categories.
new_categories need to include all old categories and no new category items.
The categories in new order.
Whether or not the categorical is treated as a ordered categorical. If not given, do not change the ordered information.
Whether or not to reorder the categories inplace or return a copy of this categorical with reordered categories.
Deprecated since version 3.2.0.
Categorical with removed categories or None if inplace=True.
inplace=True
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.
Examples
>>> s = ps.Series(list("abbccc"), dtype="category") >>> s 0 a 1 b 2 b 3 c 4 c 5 c dtype: category Categories (3, object): ['a', 'b', 'c']
>>> s.cat.reorder_categories(['c', 'b', 'a'], ordered=True) 0 a 1 b 2 b 3 c 4 c 5 c dtype: category Categories (3, object): ['c' < 'b' < 'a']