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

CategoricalAccessor.as_ordered(inplace: bool = False) Optional[SeriesOrIndex]#

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.

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]