首页 > 解决方案 > Pandas 使用 pandas 数据帧的索引来更新同一索引上的另一个数据帧

问题描述

我有 2 个熊猫数据框。我正在尝试使用基于匹配索引的df值进行更新。df2

df
    Url_Sub_Fld     ip
0   tel             na
1   li              na
2   192.22.25.26    192.22.25.26

df2
   Url_Sub_Fld
1  test_string

期望的输出:

df
    Url_Sub_Fld     ip
0   tel             na
1   test_string     na
2   192.22.25.26    192.22.25.26

标签: pythonpandas

解决方案


已经 22 小时没有答案,所以我将发布 anky_91 的评论,因为这是我用来解决问题的方法。

df.update(df2['Url_Sub_Fld'])

推荐阅读