Skip to main content
`Ctrl`+`K`

# pandas.Series.cat.as_ordered

Series.cat.as_ordered()

  Set the Categorical to be ordered.

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

  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

  For `pandas.CategoricalIndex`:

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