Pandas SQL equivalent for non-equal clause

I do not see this in the SQL comparison documentation for Pandas. What would be the equivalent of this SQL in Pandas?

select a.var1, a.var2, b.var1, b.var2 from tablea a, tableb b where a.var1=b.var1 and a.var2=b.var2 and a.var3 <> b.var3 

I have a merge code as follows:

 df = pd.merge(a, b, on=['VAR1','VAR2'], how='inner') 

How to include the "not equal" part?

 and a.var3 <> b.var3 
+5
source share
1 answer

You can request the resulting frame:

 a.merge(b, on=['VAR1','VAR2']).query('VAR3_x != VAR3_y') 
+9
source

Source: https://habr.com/ru/post/1271309/


All Articles