pandas.Series.cat.remove_unused_categories #
- 系列.cat。remove_unused_categories ( * args , ** kwargs ) [来源] #
删除不使用的类别。
- 返回:
- 分类的
未使用的类别已被删除。
也可以看看
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']