First question on SO, very new to pandas and still a little shaky on the terminology: I'm trying to figure out the proper syntax/sequence of operations on a dataframe to be able to group by column B, find the max (or min) corresponding value for each group in column C, and retrieve the corresponding value for that in column A.
Suppose this is my dataframe:
name type votes
bob dog 10
pete cat 8
fluffy dog 5
max cat 9
Using df.groupby('type').votes.agg('max')
returns:
dog 10
cat 9
So far, so good. However, I'd like to figure out how to return this:
dog 10 bob
cat 9 max
I've gotten as far as df.groupby(['type', 'votes']).name.agg('max')
, though that returns
dog 5 fluffy
10 bob
cat 8 pete
9 max
... which is fine for this pretend dataframe, but doesn't quite help when working with a much larger one.
Thanks very much!