pyspark.pandas.CategoricalIndex.as_ordered

CategoricalIndex.as_ordered(inplace: bool = False) → Optional[pyspark.pandas.indexes.category.CategoricalIndex]

Set the Categorical to be ordered.

Parameters
inplacebool, default False

Whether or not to set the ordered attribute in-place or return a copy of this categorical with ordered set to True.

Returns
CategoricalIndex or None

Ordered Categorical or None if inplace=True.

Examples

>>> idx = ps.CategoricalIndex(list("abbccc"))
>>> idx  
CategoricalIndex(['a', 'b', 'b', 'c', 'c', 'c'],
                 categories=['a', 'b', 'c'], ordered=False, dtype='category')
>>> idx.as_ordered()  
CategoricalIndex(['a', 'b', 'b', 'c', 'c', 'c'],
                 categories=['a', 'b', 'c'], ordered=True, dtype='category')