pandas.CategoricalIndex.add_categories #

分类索引。add_categories ( * args , ** kwargs ) [来源] #

添加新类别。

new_categories将包含在类别中的最后/最高位置,并且在此调用后将直接不使用。

参数
new_categories类别或类似列表的类别

要包含的新类别。

返回
分类的

添加了新类别的分类。

加薪
值错误

如果新类别包含旧类别或未验证为类别

也可以看看

rename_categories

重命名类别。

reorder_categories

重新排序类别。

remove_categories

删除指定的类别。

remove_unused_categories

删除不使用的类别。

set_categories

将类别设置为指定的类别。

例子

>>> c = pd.Categorical(['c', 'b', 'c'])
>>> c
['c', 'b', 'c']
Categories (2, object): ['b', 'c']
>>> c.add_categories(['d', 'a'])
['c', 'b', 'c']
Categories (4, object): ['b', 'c', 'd', 'a']