使用<>合并2个数据帧条件

时间:2016-05-16 16:54:05

标签: python pandas dataframe merge

我有两个DataFrame个对象:

  • df1columns = [a, b, c]
  • df2columns = [d, e]

我想将df1df2合并,使用sql中的pandas等效内容:

select * from df1 inner join df2 on df1.b=df2.e and df1.b <> df2.d and df1.c = 0

1 个答案:

答案 0 :(得分:1)

以下一系列步骤可以帮助您:

df1 = df[df1.c==0]
merged = df1.merge(df2, left_on='b', right_on='e')
merge = merged[merged.b != merged.d]