如何对多个列进行分组并找到其他列的总和?蟒蛇

问题描述

我有两个df:

df1

    Name     Country      E-mail            2010   2011
0   Jack      India     [email protected]     25     35
1   Jill    Australia   [email protected]     15     20

df2

    Name     Country      E-mail            2010   2011
0   Berry    America    Berry@example.com    45     25
1   Jack      India     [email protected]      5     10

Desired Output

df3

    Name     Country      E-mail            2010   2011
0   Jack      India     [email protected]     30     45      #add the values from df1 and df2
1   Jill    Australia   [email protected]     15     20
2   Berry    America    Berry@example.com    45     25

我使用了此代码pd.concat([df,df2]).groupby("Name",as_index=False).sum(),该代码仅按名称分组。如何合并其他两列“国家”和“电子邮件”。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)