I am looking to index the following pandas dataframe with the following sample values. The dataframe has a lot of duplicates.
ID AccountName
83 CHRISTIAN UNIVERSITY
83 CHRISTIAN UNIVERSITY
83 CHRISTIAN UNIVERSITY
83 CHRISTIAN UNIVERSITY
104 UNIVERSITY
104 UNIVERSITY
1740 ELECTRIC CORPORATIO
1740 ELECTRIC CORPORATIO
1740 ELECTRIC CORPORATIO
1740 ELECTRIC CORPORATIO
...
The resulting dataframe should be the following.
ID index AccountName
83 1 CHRISTIAN UNIVERSITY
83 1 CHRISTIAN UNIVERSITY
83 1 CHRISTIAN UNIVERSITY
83 1 CHRISTIAN UNIVERSITY
104 2 UNIVERSITY
104 2 UNIVERSITY
1740 3 ELECTRIC CORPORATIO
1740 3 ELECTRIC CORPORATIO
1740 3 ELECTRIC CORPORATIO
1740 3 ELECTRIC CORPORATIO
...
Does anyone have an fast and efficient way of doing this?
df.groupby('AccountName').ngroup() + 1