I have a dataframe with this type of data (too many columns):
col1 int64 col2 int64 col3 category col4 category col5 categ
This works for me:
pandas.factorize( ['B', 'C', 'D', 'B'] )[0]
Output:
[0, 1, 2, 0]