将值与Dataframe Python中的特定行字段进行匹配

时间:2017-12-06 20:19:33

标签: python pandas dataframe matching

考虑两个数据帧: df 1:

ID    value1    value2    result
1     50        -50       1111
2     20        -20       2222
3     -75.50    25        3333

df 2:

ID    value3    value4    result
101   20        -20       
201   -75.50    25        
756   50        -50

如何使用Python将结果与正确的列匹配?

答案是:

ID    value3    value4    result
101   20        -20       2222
201   -75.50    25        3333
756   50        -50       1111

1 个答案:

答案 0 :(得分:0)

了解合并 https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html

pd.merge( df1, df2,
          left_on = ["value1","value2"],
          right_on = ["value3","value4"] )