I did the for
command, to know how many times the ID repeats in the dateframe
, now I need to create a column indexing the total in the respective ID.
In short, I need a column with the repeat total of df['ID']
, how to index a total of the groupby command?
test = df['ID'].sort_values(ascending=True)
rep = 0
for k in range(0,len(test)-1):
if(test[k]==test[k+1]):
rep += 1
if(k==len(test)-2):
print(test[k],',', rep+1)
else:
print(test[k],',', rep+1)
rep = 0
out:
> 7614381 , 1
> 349444 , 5
> 4577800 ,7