How to deal with this logic in pandas
问题 I have a data frame like following below. coutry flag 0 China red 1 Russia green 2 China yellow 3 Britain yellow 4 Russia green ...................... In df['country'], you can see many different country names. I want to set the first appear country as 1, the second as 2. The flag is the same logic.So you can see the result is: coutry flag 0 1 1 1 2 2 2 1 3 3 3 3 4 2 2 But I don't know how to achieve this logic in python. Thank you. Moreover when I get the result data frame, I want to have an