【发布时间】:2021-07-15 17:22:20
【问题描述】:
我有一个如下所示的数据框:
Company Name Organisation Name Amount
10118 Vifor Pharma UK Ltd Welsh Assoc for Gastro & Endo 2700.00
10119 Vifor Pharma UK Ltd Welsh IBD Specialist Group, 169.00
10120 Vifor Pharma UK Ltd West Midlands AHSN 1200.00
10121 Vifor Pharma UK Ltd Whittington Hospital 63.00
10122 Vifor Pharma UK Ltd Ysbyty Gwynedd 75.93
我如何对Amount 求和并计算Organisation Name,以获得一个看起来像这样的新数据框?
Company Name Organisation Count Amount
10118 Vifor Pharma UK Ltd 5 11000.00
我知道如何求和或个数:
df.groupby('Company Name').sum()
df.groupby('Company Name').count()
但不是如何做到这两点!
【问题讨论】:
标签: python pandas dataframe group-by pandas-groupby