📜  Pandas groupby 聚合多个列 - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:07.430000             🧑  作者: Mango

代码示例4
def f(x):
    d = {}
    d['a_sum'] = x['a'].sum()
    d['a_max'] = x['a'].max()
    d['b_mean'] = x['b'].mean()
    d['c_d_prodsum'] = (x['c'] * x['d']).sum()
    return pd.Series(d, index=['a_sum', 'a_max', 'b_mean', 'c_d_prodsum'])

df.groupby('group').apply(f)