[enter image description here][I have ID column and want to add count for ids like in count column in pd dataframe. I want to do that using while loop. I tried this but I am getting never ending loop. ID:1,1,1,2,2,3,3,3,4,5,6 count must be COUNT:1,2,3,1,2,1,2,3,1,1,1
i=1
sum=1
n=len(df)
while i < n:
if df.loc[i,"ID"]=df.loc[i-1,"ID"]:
sum+=1
df.loc[i,"Count"]=sum
i+=1
else:
i=1