pyspark.pandas.CategoricalIndex.remove_unused_categories#
- CategoricalIndex.remove_unused_categories()[source]#
Remove categories which are not used.
- Returns
- catCategoricalIndex
Categorical with unused categories dropped
See also
rename_categoriesRename categories.
reorder_categoriesReorder categories.
add_categoriesAdd new categories.
remove_categoriesRemove the specified categories.
set_categoriesSet the categories to the specified ones.
Examples
>>> idx = ps.CategoricalIndex(list("abbccc"), categories=['a', 'b', 'c', 'd']) >>> idx CategoricalIndex(['a', 'b', 'b', 'c', 'c', 'c'], categories=['a', 'b', 'c', 'd'], ordered=False, dtype='category')
>>> idx.remove_unused_categories() CategoricalIndex(['a', 'b', 'b', 'c', 'c', 'c'], categories=['a', 'b', 'c'], ordered=False, dtype='category')