使用pandas中的条件匹配两个数据帧之间的值

时间:2017-11-20 06:32:17

标签: python pandas dataframe data-analysis

我有两个数据帧,

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

我试图通过比较df1和df2来更新df1。 df1 ["值"]将有df2 ["值"]等等。如果df1和df2中存在一个值,那么我想在df1中映射相应的df2 [" Names"] [" Names"]

我想要的输出是

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

提前致谢!

0 个答案:

没有答案