cudf.core.column.categorical.CategoricalAccessor.remove_categories#
- CategoricalAccessor.remove_categories(removals: Any, inplace: bool = False) Optional[SeriesOrIndex] #
Remove the specified categories.
removals must be included in the old categories. Values which were in the removed categories will be set to null.
- Parameters:
- removalscategory or list-like of category
The categories which should be removed.
- inplacebool, default False
Whether or not to remove the categories inplace or return a copy of this categorical with removed categories.
Deprecated since version 23.04: The inplace parameter is is deprecated and will be removed in a future version of cudf. Removing categories will always return a new Categorical object.
- Returns:
- cat
Categorical with removed categories or None if inplace.
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.remove_categories([1]) 0 10 1 <NA> 2 <NA> 3 2 4 10 5 2 6 10 dtype: category Categories (2, int64): [2, 10] >>> 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.remove_categories([10], inplace=True) >>> s 0 <NA> 1 1 2 1 3 2 4 <NA> 5 2 6 <NA> dtype: category Categories (2, int64): [1, 2]