Pandas: Group by two columns to get sum of another column

前端 未结 1 1539
别那么骄傲
别那么骄傲 2021-01-04 21:40

I look most of the previously asked questions but was not able to find answer for my question:

I have following data.frame

           id   year mont         


        
1条回答
  •  有刺的猬
    2021-01-04 22:09

    This should be an efficient way:

    sum_df = df.groupby(['year','month']).agg({'score': 'sum', 'num_attempts': 'sum'})
    

    0 讨论(0)
提交回复
热议问题