Reputation: 161
I have a very large dataframe of experimental data. I have a Multi index that define each samples (A,B) with the data in columns x,y,z:
A B x y z
0.1 0.1 0.1 0 -1
0.1. 0.1 0.2 -5 0
0.1 0.1 0.4 -10 0
0.1 0.2 0.6 0 -1
0.1 0.2 0.3 -4 -0.4
0.1 0.2 0.1 -9 0
0.1 0.5 0.2 0 0
0.1 0.5 0.4 -2 0
0.1 0.5 0.3 -5 0
0.2 0.1 0.2 -1 -1
0.2 0.1 0.1 -2 -2
0.2 0.1 0.4 -3 0
...
I have a complicated condition to fill but essentially:
Expected output:
A B x y z
0.1. 0.1 0.2 -5 0
0.1 0.2 0.1 -9 0
0.1 0.5 0.2 0 0
0.2 0.1 0.4 -3 0
Thanks in advance.
Upvotes: 1
Views: 100
Reputation: 161
output=(df.loc[df['z']==0]).groupby(['A','B'])['y'].max()
Thanks to Narendra Prasath for pointing me in the right direction.
Upvotes: 0
Reputation: 1531
you can try this
df.loc[df[df["z"] == 0].groupby(["A","B"])['y'].idxmax()].reset_index(drop=True)
Upvotes: 3