我有3个数据框,其中有一个要合并的字符串列和两个要累加的相似列
df1:
index user x y
1 john 5 6
2 pete 10 10
df2:
index user x y
1 john 1 1
2 pete 2 2
3 nash 5 5
df3:
index user x y
1 nash 6 7
2 john 2 4
3 kyle 3 3
我想要: df4:
index user x y
1 john 8 11
2 pete 12 12
3 nash 11 12
4 kyle 3 3
答案 0 :(得分:1)
首先尝试pandas.concat
,然后groupby
public class UserDetails {
private int userId;
private String name;
private String email;
private String phone;
}
import pandas as pd
pd.concat([df1, df2, df3]).groupby(["user"], as_index=False)[['x', 'y']].sum()