pyspark.pandas.Series.cat.remove_categories

cat.remove_categories(removals: Union[pandas.core.indexes.base.Index, Any, List], inplace: bool = False) → Optional[ps.Series]

Remove the specified categories.

removals must be included in the old categories. Values which were in the removed categories will be set to NaN

Parameters
removalscategory or list of categories

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.

Returns
Series or None

Categorical with removed categories or None if inplace=True.

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

>>> 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.remove_categories('b')  
0      a
1    NaN
2    NaN
3      c
4      c
5      c
dtype: category
Categories (2, object): ['a', 'c']