print (pd.factorize(L)[0]) [0 1 2 1 0]
L = ['ABC', 'DEF', 'GHI', 'DEF', 'ABC'] print (np.unique(L, return_inverse=True)[1]) [0 1 2 1 0]