Apply different functions to different items in group object: Python pandas

后端 未结 3 1709
暗喜
暗喜 2021-02-03 11:46

Suppose I have a dataframe as follows:

In [1]: test_dup_df

Out[1]:
                  exe_price exe_vol flag 
2008-03-13 14:41:07  84.5    200     yes
2008-03-13         


        
3条回答
  •  广开言路
    2021-02-03 12:03

    Not terribly familiar with pandas, but in pure numpy you could do:

    tot_vol = np.sum(grouped['exe_vol'])
    avg_price = np.average(grouped['exe_price'], weights=grouped['exe_vol'])
    

提交回复
热议问题