pandas.Categorical.add_categories — pandas 3.0.0.dev0+2104.ge637b4290d documentation (original) (raw)
Categorical.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:
Categorical
Categorical with new categories added.
Raises:
ValueError
If the new categories include old categories or do not validate as categories
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']