pyspark.pandas.Series.cat.add_categories

cat.add_categories(new_categories: Union[pandas.core.indexes.base.Index, Any, List]) → Optional[ps.Series]

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
Series or None

Categorical with new categories added or None if inplace=True.

Raises
ValueError

If the new categories include old categories or do not validate as categories

See also

rename_categories

Rename categories.

reorder_categories

Reorder categories.

remove_categories

Remove the specified categories.

remove_unused_categories

Remove categories which are not used.

set_categories

Set the categories to the specified ones.

Examples

>>> s = ps.Series(list("abbccc"), dtype="category")
>>> s  
0    a
1    b
2    b
3    c
4    c
5    c
dtype: category
Categories (3, object): ['a', 'b', 'c']
>>> s.cat.add_categories('x')  
0    a
1    b
2    b
3    c
4    c
5    c
dtype: category
Categories (4, object): ['a', 'b', 'c', 'x']