pandas.Series.cat.remove_categories#

Series.cat.remove_categories(*args, **kwargs)[源代码]#

删除指定的类别。

removals 必须包含在旧类别中。存在于被移除类别中的值将被设置为 NaN。

Parameters:
removalscategory or list of categories

应被移除的类别。

Returns:
Categorical

已移除类别的 Categorical。

Raises:
ValueError

如果移除项未包含在类别中

参见

rename_categories

重命名类别。

reorder_categories

重新排序类别。

add_categories

添加新类别。

remove_unused_categories

删除未使用的类别。

set_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']