pandas.Series.cat.remove_unused_categories#
- Series.cat.remove_unused_categories(*args, **kwargs)[源代码]#
删除不使用的类别。
- 参数
- inplace布尔值,默认为False
是就地删除未使用的类别,还是返回已删除未使用的类别的此分类目录的副本。
1.2.0 版后已移除.
- 退货
- cat明确或无
如果删除未使用的类别,则为分类,否则为无
inplace=True
。
参见
rename_categories
重命名类别。
reorder_categories
重新排序类别。
add_categories
添加新类别。
remove_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[2] = 'a' >>> c[4] = 'c' >>> c ['a', 'c', 'a', 'c', 'c'] Categories (4, object): ['a', 'b', 'c', 'd']
>>> c.remove_unused_categories() ['a', 'c', 'a', 'c', 'c'] Categories (2, object): ['a', 'c']