pandas.Series.cat.add_categories#
- Series.cat.add_categories(*args, **kwargs)[源代码]#
添加新类别。
new_categories 将被包括在类别中的最后/最高位置,并且将在这次调用后直接不使用。
- 参数
- new_categories类别或类似于类别的列表
将包括的新类别。
- inplace布尔值,默认为False
是否就地添加类别或返回此类别的副本以及添加的类别。
1.3.0 版后已移除.
- 退货
- cat明确或无
添加了新类别的类别或无类别(如果
inplace=True
。
- 加薪
- ValueError
如果新类别包括旧类别或未验证为类别
参见
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']