pandas.CategoricalIndex.add_categories#
- CategoricalIndex.add_categories(new_categories)[source]#
Add new categories.
new_categories will be included at the last/highest place in the categories and will be unused directly after this call.
- Parameters:
- new_categoriescategory or list-like of category
The new categories to be included.
- Returns:
- CategoricalIndex
CategoricalIndex with new categories added.
- Raises:
- ValueError
If the new categories include old categories or do not validate as categories
See also
CategoricalIndex.rename_categoriesRename categories.
CategoricalIndex.reorder_categoriesReorder categories.
CategoricalIndex.remove_categoriesRemove the specified categories.
CategoricalIndex.remove_unused_categoriesRemove categories which are not used.
CategoricalIndex.set_categoriesSet the categories to the specified ones.
Examples
>>> ci = pd.CategoricalIndex(["c", "b", "c"]) >>> ci CategoricalIndex(['c', 'b', 'c'], categories=['b', 'c'], ordered=False, dtype='category')
>>> ci.add_categories(["d", "a"]) CategoricalIndex(['c', 'b', 'c'], categories=['b', 'c', 'd', 'a'], ordered=False, dtype='category')