你能帮我,如何做vlookup或pd合并在空白的excel列中的特定列。我只知道如何进行pd合并,该值将作为新列出现。
我有一个数据文件df1
index id Value Info
0 0 A1 xxx
1 1 A2 xxx
2 2 A3 xxx
3 3 A4 xxx 还有这个数据帧df2
index id Value
0 0 A1 Apple
1 1 A2 Orange
2 2 A3 Banana
3 3 A4 Grape 我希望在合并df1和df2时获得以下结果
index id Value Info
0 0 A1 Apple xxx
1 1 A2 Orange xxx
2 2 A3 Banana xxx
3 3 A4 Grape xxx 发布于 2022-06-23 04:58:31
考虑到熊猫的操作,这可能是直接的。
df1 = pd.DataFrame({"index":[0,1,2,3],"id":["A1","A2","A3","A4"],"Info":['xx1','xx2','xx3','xx4']})
df1
df2 = pd.DataFrame({"index":[0,1,2,3],"id":["A1","A2","A3","A4"],"Value":['Apple','Orange','Banana','Grape']})
df2你可以用:
df1.merge(df2)它提供了以下输出:
index id Info Value
0 0 A1 xx1 Apple
1 1 A2 xx2 Orange
2 2 A3 xx3 Banana
3 3 A4 xx4 Grapehttps://stackoverflow.com/questions/72724651
复制相似问题