cudf.core.column.categorical.CategoricalAccessor.remove_categories#

CategoricalAccessor.remove_categories(removals: Any) SeriesOrIndex | None[source]#

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.

Returns:
cat

Categorical with removed categories

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]