Pandas how to apply multiple functions to dataframe

前端 未结 4 2194
粉色の甜心
粉色の甜心 2020-12-03 13:39

Is there a way to apply a list of functions to each column in a DataFrame like the DataFrameGroupBy.agg function does? I found an ugly way to do it like this:



        
4条回答
  •  时光说笑
    2020-12-03 14:36

    In the general case where you have arbitrary functions and column names, you could do this:

    df.apply(lambda r: pd.Series({'mean': r.mean(), 'std': r.std()})).transpose()
    
             mean       std
    one  5.366303  2.612738
    two  4.858691  2.986567
    

提交回复
热议问题