我对Python还不是很熟悉。我有一个看起来像这样的熊猫数据框:
0 1 2 3
55 Alice 12896399 8 45
45 Bob 16891982 0 0
90 Cybill 1800407 1 1
05 Alice 12896399 100 200
33 Bob 16891982 0.5 0
42 Bob 16891982 -1.5 -0.5
46 Bob 16891982 1 0
99 Cybill 1800407 0.00 0.00
我如何求和第2列和第3列的值,以得出每个人的结果?像这样:
Alice 108 245
Bob 0 -0.5
Cybill 1 1
预先感谢您的答复。
您可以groupby
并可以sum
在IIUC上关注IIUC :
In [13]:
df.groupby('0')[['2','3']].sum()
Out[13]:
2 3
0
Alice 108.0 245.0
Bob 0.0 -0.5
Cybill 1.0 1.0
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句