I have this df :
name
str_a
str_a
str_a
str_b
str_b
str_c
str_c
In the column name I got different str, I want to create another column named number which has for the first row 0 then each time the previuous name is different from the next one, it adds +1 to the previous number. The expected result would be :
name number
str_a 0
str_a 0
str_a 0
str_b 1
str_b 1
str_c 2
str_c 2
Is there a way to do that without a loop ?
Thanks !