Ennumerate categorical items of a column

Hello,

Here’s what I am trying to do (Col2 is the desired result)

Col1       Col2
100         1 
100         2 
100         3
101         1
102         1 
102         2
102         3
102         4
102         5
103         1
103         2

I try to ennumerate the occurrances of values of Col1, here’s the code I tried

data['Col2'] = list(enumerate(data['col1'], 1))

but it simply creates a list.

I would be grateful if anyone could shed some light on this.

Sincerely,

Josep Maria

Here’s the answer:

data["Col2"] = data.groupby("Col1").cumcount()+1