2017-08-28 59 views
5

我在熊貓的SQL比較文檔中沒有看到這一點。 Pandas中這個SQL的等價物是什麼?「不等於」條款的熊貓SQL等效項

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 

我有合併代碼如下:

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

如何納入 '不等於' 部分?

and a.var3 <> b.var3 
+0

後'merge'加上'df.loc [df.var3_y = df.var3_x,:]':) – Wen

回答

9

您可以查詢得到的框架:

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

不經常看見你回答一個簡單的問題;-) –

+0

不經常我看到你回答一個簡單的問題: - )+ 1 – Wen

+0

'!='是相當於'<>'的蟒蛇 – chicocvenancio