I have a dataframe, let's call it 'data', as follows:
index ID name
0 23 aaa
1 42 bbb
2 23 aab
3 42 bbb
4 42 bbb
...
I want to count the occurences of ID and create an extra column for that by which I can sort. Additionally I want to add the names to sets, because they might differ. Something like this (additional index optional):
count ID name
3 42 {bbb}
2 23 {aaa, aab}
I know the solution is somewhere in the group_by() function. I can put the names into sets with data.groupby('ID')['name'].apply(set).reset_index() but how do I additionally count the occurrences of ID and add the numbers to the DataFrame correctly? I'm standing on the hose, as the German says. Thanks a lot!