Python Pandas: Passing Multiple Functions to agg() with Arguments

后端 未结 1 1934
情话喂你
情话喂你 2021-02-07 11:49

I\'m struggling to figure out how to combine two different syntaxes for pandas\' dataframe.agg() function. Take this simple data frame:

df = pd.Dat         


        
相关标签:
1条回答
  • 2021-02-07 12:51

    Well, the docs on aggregate are in fact a bit lacking. There might be a way to handle this with the correct passing of arguments, and you could look into the source code of pandas for that (perhaps I will later).

    However, you could easily do:

    df.groupby('A').agg([np.mean, lambda x: np.std(x, ddof=0)])
    

    And it would work just as well.

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