Skip to main content
`Ctrl`+`K`

# pandas.Series.cat.codes

Series.cat.codes

  Return Series of codes as well as the index.

  The codes are integer indicators for the position of each value in the categories. Uncategorized values (i.e., NaN) are assigned a code of `-1`.

  See also

  `Series.cat.categories`

    Return the categories of this categorical.

  `Series.cat.as_ordered`

    Set the Categorical to be ordered.

  `Series.cat.as_unordered`

    Set the Categorical to be unordered.

  Examples

      >>> raw_cate = pd.Categorical(["a", "b", None, "a"], categories=["a", "b"])
      >>> ser = pd.Series(raw_cate)
      >>> ser.cat.codes
      0   0
      1   1
      2  -1
      3   0
      dtype: int8