尝试这个:
In [110]: (df.groupby('Company Name') .....: .agg({'Organisation Name':'count', 'Amount': 'sum'}) .....: .reset_index() .....: .rename(columns={'Organisation Name':'Organisation Count'}) .....: )Out[110]: Company Name Amount Organisation Count0 Vifor Pharma UK Ltd 4207.93 5
或者如果您不想重置索引:
df.groupby('Company Name')['Amount'].agg(['sum','count'])
要么
df.groupby('Company Name').agg({'Amount': ['sum','count']})
演示:
In [98]: df.groupby('Company Name')['Amount'].agg(['sum','count'])Out[98]: sum countCompany NameVifor Pharma UK Ltd 4207.93 5In [99]: df.groupby('Company Name').agg({'Amount': ['sum','count']})Out[99]:Amount sum countCompany NameVifor Pharma UK Ltd 4207.93 5
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)