I have a dataframe that looks like this(see the same dataframe in picture):
transaction_datetime
client_id store_id
0 81 22
1 3166 5
3709 7
5365 29
10440 7
What I want to get is a grouping, where for each client_id I get the store_id where transaction_datetime is maximum. That is: for client_id 0 I get 81(because there is only one store), for client_id 1 I get 5365.
I see some ways to make it work, e.g.
grouping.reset_index().sort_values(by=['client_id', 'transaction_time', 'store_id'], ascending=[True, False, False]).drop_duplicates('client_id')
But it doesn't look nice. Is there a better way?
grouping.reset_index().groupby('client_id').max() yields maximum values for each column separately(which is expected, I suppose)