cudf.core.column.categorical.CategoricalAccessor.as_ordered#

CategoricalAccessor.as_ordered(inplace: bool = False) SeriesOrIndex | None#

Set the Categorical to be ordered.

Parameters:
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.02: The inplace parameter is is deprecated and will be removed in a future version of cudf. Setting categories as ordered will always return a new Categorical object.

Returns:
Categorical

Ordered Categorical or None if inplace.

Examples

>>> import cudf
>>> s = cudf.Series([10, 1, 1, 2, 10, 2, 10], dtype="category")
>>> s
0    10
1     1
2     1
3     2
4    10
5     2
6    10
dtype: category
Categories (3, int64): [1, 2, 10]
>>> s.cat.as_ordered()
0    10
1     1
2     1
3     2
4    10
5     2
6    10
dtype: category
Categories (3, int64): [1 < 2 < 10]
>>> s.cat.as_ordered(inplace=True)
>>> s
0    10
1     1
2     1
3     2
4    10
5     2
6    10
dtype: category
Categories (3, int64): [1 < 2 < 10]