pandas.Categorical.remove_categories — pandas 3.0.0.dev0+2099.g3832e85779 documentation (original) (raw)
Categorical.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
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']