pyspark.pandas.CategoricalIndex.as_ordered#

CategoricalIndex.as_ordered()[source]#

Set the Categorical to be ordered.

Returns
CategoricalIndex

Ordered Categorical

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')