pandas.Series.cat.as_ordered#
- Series.cat.as_ordered(*args, **kwargs)[source]#
Set the Categorical to be ordered.
- Returns:
- Categorical
Ordered Categorical.
See also
as_unordered
Set the Categorical to be unordered.
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
>>> ci = pd.CategoricalIndex(["a", "b", "c", "a"]) >>> ci.ordered False >>> ci = ci.as_ordered() >>> ci.ordered True