I have a DataFrame object df
. One of the column values in df
is ID
There are many rows with the same ID.
I want to create a new columns num_totals
that counts the number of observation for each ID. For example, something like this:
ID | Num Totals
1 | 3
1 | 3
1 | 3
2 | 2
2 | 2
3 | 3
3 | 3
3 | 3
4 | 1
What's the fastest way to do this in Pandas?