pandas.Series.cat.remove_categories#

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

删除指定的类别。

removals 必须包括在旧的类别中。删除的类别中的值将设置为NAN

参数
removals类别或类别列表

应删除的类别。

inplace布尔值,默认为False

是否就地删除类别或返回此类别的副本以及删除的类别。

1.3.0 版后已移除.

退货
cat明确或无

带有已删除类别的类别或无类别,如果 inplace=True

加薪
ValueError

如果删除不包含在类别中

参见

rename_categories

重命名类别。

reorder_categories

重新排序类别。

add_categories

添加新类别。

remove_unused_categories

删除不使用的类别。

set_categories

将类别设置为指定类别。

示例

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