pandas.CategoricalIndex.remove_categories#
- CategoricalIndex.remove_categories(removals)[source]#
Remove the specified categories.
The
removalsargument must be a subset of the current categories. Any values that were part of the removed categories will be set to NaN.- Parameters:
- removalscategory or list of categories
The categories which should be removed.
- Returns:
- CategoricalIndex
CategoricalIndex with removed categories.
- Raises:
- ValueError
If the removals are not contained in the categories
See also
CategoricalIndex.rename_categoriesRename categories.
CategoricalIndex.reorder_categoriesReorder categories.
CategoricalIndex.add_categoriesAdd new categories.
CategoricalIndex.remove_unused_categoriesRemove categories which are not used.
CategoricalIndex.set_categoriesSet the categories to the specified ones.
Examples
>>> ci = pd.CategoricalIndex(["a", "c", "b", "c", "d"]) >>> ci CategoricalIndex(['a', 'c', 'b', 'c', 'd'], categories=['a', 'b', 'c', 'd'], ordered=False, dtype='category')
>>> ci.remove_categories(["d", "a"]) CategoricalIndex([nan, 'c', 'b', 'c', nan], categories=['b', 'c'], ordered=False, dtype='category')