For instance, suppose this is the dataframe I have:
row object_id
1 1024
2 1024
3 1024
4 1032
5 1032
6 1048
... ...
I want to create a column occurence_num
as follows:
row object_id occurence_num
1 1024 1 # starts count
2 1024 2
3 1024 3
4 1032 1 # restarts count since object_id has changed
5 1032 2
6 1048 1 # restarts count since object_id has changed
... ... ...
A method of doing it in SQL would also be helpful, but I want to be able to do it using pandas.
NOTE: I've found a way to do it in excel here.