I have a dataframe 'gt' like this:
org group org1 1 org2 1 org3 2 org4 3 org5 3 org6 3
and I would like to add a “count” column to the gt dataframe to count the number of group members, expected results as follows:
org group count org1 1 2 org2 1 2 org3 2 1 org4 3 3 org5 3 3 org6 3 3
I know how to do this on one element of the group, but I don’t know how to make the counter repeat for all elements of the group, here is the code I used:
gtcounts = gt.groupby('group').count()
Does anyone help?
python pandas count group-by
UserYmY
source share