matching values between two dataframes with a condition in pandas

我们两清 提交于 2019-12-24 07:57:22

问题


I have two dataframes,

df1,

    Values
 0  Sri
 1  pyd
 2  NaN
 3  sri, is
 4  keyboard
 5  kumar,cricketer

df2,

 Values         | Names
 Sri            | Sri is a good player
 NaN            | NaN   
 sri, is        | Sri is a good player
kumar,cricketer | Kumar is a cricketer

I am trying to update the df1 by comparing df1 and df2. df1["Values"] will have df2["Values"] and more. if a value present in df1 and df2 then I want to map the corresponding df2["Names"] in df1["Names"]

my desired output is

df1,

    Values            |    Names
 0  Sri               |  Sri is a good player
 1  pyd               |  NaN   
 2  NaN               |  NaN   
 3  sri, is           |  Sri is a good player
 4  keyboard          |  NaN
 5  kumar,cricketer   |  Kumar is a cricketer

Thanks in advance!

来源:https://stackoverflow.com/questions/47386216/matching-values-between-two-dataframes-with-a-condition-in-pandas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!