I have a data frame as follows:
df = pd.DataFrame({'year': [2010, 2011, 2012, 2015,2016,2017],
'sales': [10, 12, 13, 9, 11,7],
'Groups': ['AA', 'BB', 'AA', 'AA', 'CC', 'CC']})
what I am trying to do is to map the 'Groups' column with an integer index value so the same group members assigned the same index number. Somrthing like this:
Index year sales Groups
1 2010 10 AA
2 2011 12 BB
1 2012 13 AA
1 2015 9 AA
3 2016 11 CC
3 2017 7 CC
I was thinking to use set_index, but not sure if that is the right approach.
what I am trying to do is to map the 'Groups' column with an index value so the same group members assigned the same index number. Something like this:
Index year sales Groups
1 2010 10 AA
2 2011 12 BB
1 2012 13 AA
1 2015 9 AA
3 2016 11 CC
3 2017 7 CC
Thanks for any help.