pandas.CategoricalIndex.add_categories#

CategoricalIndex.add_categories(*args, **kwargs)[源代码]#

添加新类别。

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

Parameters:
new_categoriescategory 或 list-like of category

要包含的新类别。

Returns:
Categorical

添加了新类别的 Categorical。

Raises:
ValueError

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

参见

rename_categories

重命名类别。

reorder_categories

重新排序类别。

remove_categories

删除指定的类别。

remove_unused_categories

删除未使用的类别。

set_categories

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

Examples

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