简体   繁体   中英

Pandas SQL equivalent for 'not 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 the merge code as follows:

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

How do I incorporate the 'not equal' portion?

and a.var3 <> b.var3

您可以查询结果框架:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM