pandas.CategoricalIndex.remove_unused_categories#
- CategoricalIndex.remove_unused_categories(*args, **kwargs)[源代码]#
删除未使用的类别。
- Returns:
- Categorical
已移除未使用类别的 Categorical。
参见
rename_categories重命名类别。
reorder_categories重新排序类别。
add_categories添加新类别。
remove_categories删除指定的类别。
set_categories将类别设置为指定的类别。
Examples
>>> 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']