Laurent
Laurent

Reputation: 69

Pandas get all rows by max values for the second index

I'm trying to get the row with highest frequency. I counted the frequency of which department each user go to, but now I need to associate each user to a department they frequent which would be the two index columns department and department_id.

enter image description here enter image description here

enter image description here

-Edit Please forgive my stupidity. This drop box is a link to the csv file. https://www.dropbox.com/s/ttnmraxptpcw61c/user_department_freq.csv?dl=0

Upvotes: 0

Views: 239

Answers (1)

BENY
BENY

Reputation: 323266

You can do sort_values, the groupby with tail

s=df.sort_values('order_id').groupby(level=0).tail(1)

Upvotes: 1

Related Questions