【发布时间】:2019-02-27 16:48:58
【问题描述】:
我有一个像这样的数据集:
time(secs) setup
40 setup1
30 setup1
20 setup1
10 setup2
20 setup2
10 setup1
30 setup1
30 setup2
40 setup2
10 setup3
20 setup3
我想获得 pandas dataframe 中的行总和,具体取决于类似的 setup 值:
time(secs) setup
90 setup1
30 setup2
40 setup1
70 setup2
30 setup3
但是通过使用groupby()函数:
df.groupby(['setup']).sum()
我得到的结果是:
setup time
setup1 130
setup2 100
setup3 30
请帮助解决这个问题...
谢谢!!!
【问题讨论】:
标签: python-2.7 pandas sum grouping pandas-groupby