Multiple aggregations of the same column using pandas GroupBy.agg()

前端 未结 3 2212
太阳男子
太阳男子 2020-11-22 11:32

Is there a pandas built-in way to apply two different aggregating functions f1, f2 to the same column df[\"returns\"], without having to call

3条回答
  •  猫巷女王i
    2020-11-22 11:43

    Would something like this work:

    In [7]: df.groupby('dummy').returns.agg({'func1' : lambda x: x.sum(), 'func2' : lambda x: x.prod()})
    Out[7]: 
                  func2     func1
    dummy                        
    1     -4.263768e-16 -0.188565
    

提交回复
热议问题