pandas.Series.cat.codes

Series.cat.codes