How do I do a cumcount on two groupings, id and name? For example I have:
id name 1 name1 1 name1 1 name2 2 name3 2 name3 2 name3
You can use groupby.cumcount:
groupby.cumcount
df['cumcount'] = df.groupby(['id', 'name']).cumcount() + 1 df # id name cumcount #0 1 name1 1 #1 1 name1 2 #2 1 name2 1 #3 2 name3 1 #4 2 name3 2 #5 2 name3 3