cudf.core.column.categorical.CategoricalAccessor.add_categories#
- CategoricalAccessor.add_categories(new_categories: Any, inplace: bool = False) Optional[SeriesOrIndex] #
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.
- inplacebool, default False
Whether or not to add the categories inplace or return a copy of this categorical with added categories.
Deprecated since version 23.04: The inplace parameter is is deprecated and will be removed in a future version of cudf. Adding categories will always return a new Categorical object.
- Returns:
- cat
Categorical with new categories added or None if inplace.
Examples
>>> import cudf >>> s = cudf.Series([1, 2], dtype="category") >>> s 0 1 1 2 dtype: category Categories (2, int64): [1, 2] >>> s.cat.add_categories([0, 3, 4]) 0 1 1 2 dtype: category Categories (5, int64): [1, 2, 0, 3, 4] >>> s 0 1 1 2 dtype: category Categories (2, int64): [1, 2] >>> s.cat.add_categories([0, 3, 4], inplace=True) >>> s 0 1 1 2 dtype: category Categories (5, int64): [1, 2, 0, 3, 4]