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