pandas.Series.cat.remove_categories#
- Series.cat.remove_categories(removals)[source]#
Remove the specified categories.
The
removals
argument must be a subset of the current categories. Any values that were part of the removed categories will be set to NaN.- Parameters:
- removalscategory or list of categories
The categories which should be removed.
- Returns:
- Categorical
Categorical with removed categories.
- Raises:
- ValueError
If the removals are not contained in the categories
See also
rename_categories
Rename categories.
reorder_categories
Reorder categories.
add_categories
Add new categories.
remove_unused_categories
Remove categories which are not used.
set_categories
Set the categories to the specified ones.
Examples
>>> c = pd.Categorical(["a", "c", "b", "c", "d"]) >>> c ['a', 'c', 'b', 'c', 'd'] Categories (4, object): ['a', 'b', 'c', 'd']
>>> c.remove_categories(["d", "a"]) [NaN, 'c', 'b', 'c', NaN] Categories (2, object): ['b', 'c']