pandas.CategoricalIndex.as_ordered#

CategoricalIndex.as_ordered()[source]#

Set the CategoricalIndex to be ordered.

This method returns a new CategoricalIndex with the ordered attribute set to True, enabling comparison operations between categories.

Returns:
CategoricalIndex

Ordered CategoricalIndex.

See also

CategoricalIndex.as_unordered

Set the CategoricalIndex to be unordered.

Examples

>>> ci = pd.CategoricalIndex(["a", "b", "c", "a"])
>>> ci.ordered
False
>>> ci = ci.as_ordered()
>>> ci.ordered
True