Let\'s say I have a list
l = [\'michael\',\'michael\',\'alice\',\'carter\']
I want to map it to the following:
k = [1,1,2,3
How about using Pandas?
import pandas as pd l = ['michael','michael','alice','carter'] pd.Series(l).astype('category').cat.codes.values