I have a dataframe. It is group by 'ex' as below: enter image description here Now I want to get rows which have max value in each group
Asked
Active
Viewed 1,070 times
0
-
over which column? – shai gindin Jun 06 '22 at 07:21
-
Oh sorry, I want to max value of transaction_fee column – Quang Minh Vu Jun 06 '22 at 07:23
-
I think you need df_2.groupby("ex")["transaction_fee"].max() – foxel Jun 06 '22 at 07:44
-
But I want to get the corresponding value in other columns of this max value – Quang Minh Vu Jun 06 '22 at 07:49
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jun 06 '22 at 13:34
1 Answers
1
so a quick google search and you will find out how to get relevant rows here: for your implementation:
df.groupby("ex")['transaction_fee'].max()
the other thing you should look for is how to get the corresponding indices for the original table. you could find something similar here:
for your implemtionation:
idxs = df.groupby("ex")['transaction_fee'].transform(max) == df['transaction_fee']
relevant_df = df[idxs]
cheers ✌

shai gindin
- 109
- 3