PD合并特定列

发布于 2025-02-09 21:07:53 字数 665 浏览 1 评论 0原文

您能帮我吗,如何在空白excel列中的特定列上进行vlookup或PD合并。我只知道如何进行PD合并,并且该值作为新列出现,

我有一个dataframe 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       

我希望在合并df1df2

  index id  Value   Info        
0   0   A1  Apple   xxx 
1   1   A2  Orange  xxx 
2   2   A3  Banana  xxx 
3   3   A4  Grape   xxx 

can u help me, how to do vlookup or pd merge on speccific column in the blank excel column. I just know how to do pd merge and the value come as a new column

I have a dataframe df1

  index id  Value   Info        
0   0   A1          xxx 
1   1   A2          xxx 
2   2   A3          xxx 
3   3   A4          xxx 

and also this data frame df2

  index id  Value           
0   0   A1  Apple       
1   1   A2  Orange      
2   2   A3  Banana      
3   3   A4  Grape       

I wish to get to the following outcome when merging df1 and 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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ま柒月 2025-02-16 21:07:53

考虑到熊猫的操作,这可能是直接的。

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     Grape

This could be straight forward considering pandas operations.

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

You could use:

df1.merge(df2)

which gives the below output:

index   id  Info    Value
0   0   A1  xx1     Apple
1   1   A2  xx2     Orange
2   2   A3  xx3     Banana
3   3   A4  xx4     Grape
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文