pandas.CategoricalIndex.as_ordered#

CategoricalIndex.as_ordered(*args, **kwargs)[source]#

Set the Categorical to be ordered.

Returns:
Categorical

Ordered Categorical.

Examples

For pandas.Series:

>>> ser = pd.Series(['a', 'b', 'c', 'a'], dtype='category')
>>> ser.cat.ordered
False
>>> ser = ser.cat.as_ordered()
>>> ser.cat.ordered
True

For pandas.CategoricalIndex:

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