简体   繁体   English

用python总结三个数据帧

[英]Summing up three data frames in python

I would like to sum three data frames and i want to sum based on a single column(hkd_margin) and it has to summed together based on account number. 我想对三个数据帧求和,并且我想基于一个列(hkd_margin)求和,并且必须根据帐号求和。

The data frames look like this: 数据帧如下所示:

How do I do it? 我该怎么做? Need some guidance. 需要一些指导。

I believe you need concat with aggregate sum : 我相信你需要concat与总sum

df = pd.concat([df1, df2, df3]).groupby('account_number', as_index=False)['hkd_margin'].sum()
print (df)
   account_number    hkd_margin
0              20  2.361950e+05
1              40  1.375593e+07
2              60  2.174999e+07
3              90  4.695600e+04

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM