This provides count, but I want to provide Index values for eg: 1,2,3 for one person, and new person comes again 1,2,3,4 etc.
new_df['Index']=new_df.groupby('Name Of Reporting Person')['Name Of Reporting Person'].transform('count')
CodePudding user response:
It seems like groupby().cumcount()
is what you need:
new_df['Index']=new_df.groupby('Name Of Reporting Person')['Name Of Reporting Person'].cumcount()
CodePudding user response:
use ngroup
new_df['Index'] = new_df.groupby('Name Of Reporting Person').ngroup() 1