- API reference
- pandas.CategoricalIndex
- pandas.Categ...
pandas.CategoricalIndex.add_categories#
- CategoricalIndex.add_categories(*args,**kwargs)[source]#
Add new categories.
new_categories will be included at the last/highest place in thecategories and will be unused directly after this call.
- Parameters:
- new_categoriescategory or list-like of category
The new categories to be included.
- Returns:
- Categorical
Categorical with new categories added.
- Raises:
- ValueError
If the new categories include old categories or do not validate ascategories
See also
rename_categoriesRename categories.
reorder_categoriesReorder categories.
remove_categoriesRemove the specified categories.
remove_unused_categoriesRemove categories which are not used.
set_categoriesSet the categories to the specified ones.
Examples
>>>c=pd.Categorical(['c','b','c'])>>>c['c', 'b', 'c']Categories (2, object): ['b', 'c']
>>>c.add_categories(['d','a'])['c', 'b', 'c']Categories (4, object): ['b', 'c', 'd', 'a']
On this page