Python 如何找到最大值取决于两列?

Python 如何找到最大值取决于两列?,python,pandas,dataframe,group-by,Python,Pandas,Dataframe,Group By,我有什么? 我有一个数据框,看起来像: id1 id2 max_value 0 1 3 50748.0 1 1 3 50631.0 2 1 4 55876.0 3 1 4 56424.0 4 1 5 28242.0 5 1 5 28316

我有什么?

我有一个数据框,看起来像:

      id1   id2      max_value   
0      1     3       50748.0     
1      1     3       50631.0     
2      1     4       55876.0     
3      1     4       56424.0     
4      1     5       28242.0     
5      1     5       28316.0     
我想要什么?

对于每个id1,id2,我想得到最大值。对于上述示例:

      id1   id2      max_value   
0      1     3       50748.0     
1      1     4       56424.0     
2      1     5       28316.0     

我试过什么?


我试图在groupby中使用groupby,但没有成功

答案

我找到了正确的答案:groupby有两列

df = df.groupby(['id1', 'id2'])['max_value'].agg('max').reset_index()