Vlookup在列的右侧

时间:2017-12-04 07:56:43

标签: python python-3.x pandas

我正在尝试查看列右侧的值。

DF1

       EW  WE   DA  dd     AA
0  cheese   0  300   T      T
1  dwadaw   3  400  21  31232

df 2

       AD   FA      BA  DA    daw ddwad
0  dddddd    1     300   T      T     T
1  cheese    1     400  21  31232   NaN
2  chees   dwa  waddcv   3    NaN   NaN

所需:

       AD   FA     
0  cheese    1     

我试试:

    df3 = df2[['AD', 'FA']].copy()
    df3.FA=np.where(df2.AD.isin(df1.EW),df3.FA,np.nan)
    print (df3)

我的输出与df2中的AD和FA相同

df3 = df2[df2.AD.isin(df1.EW)]提供:df3 = df2[df2.AD.isin(df1.EW)] cheese 1.0 300 T T

1 个答案:

答案 0 :(得分:0)

我认为你需要:

df3 = df2[df2.AD.isin(df1.EW)]
df3 = df3[['AD','FA']]
print (df3)
       AD FA
1  cheese  1