pandas.CategoricalIndex.codes#
- property CategoricalIndex.codes[source]#
The category codes of this categorical index.
Codes are an array of integers which are the positions of the actual values in the categories array. There is no setter.
- Returns:
- ndarray[int]
A non-writable view of the
codesarray.
See also
Categorical.from_codesMake a Categorical from codes.
CategoricalIndexAn Index with an underlying
Categorical.
Examples
>>> ci = pd.CategoricalIndex(["a", "b", "c", "a", "b", "c"]) >>> ci.codes array([0, 1, 2, 0, 1, 2], dtype=int8)
>>> ci = pd.CategoricalIndex(["a", "c"], categories=["c", "b", "a"]) >>> ci.codes array([2, 0], dtype=int8)