Python Keep other columns when using sum() with groupby

前端 未结 3 824
遥遥无期
遥遥无期 2020-12-15 06:28

I have a pandas dataframe below:

    df

    name    value1    value2  otherstuff1 otherstuff2 
0   Jack       1         1       1.19        2.39     
1   Ja         


        
3条回答
  •  半阙折子戏
    2020-12-15 07:04

    The key in the answer above is actually the as_index=False, otherwise all the columns in the list get used in the index.

    p_summ = p.groupby( attributes_list, as_index=False ).agg( {'AMT':sum })
    

提交回复
热议问题