Reputation: 3419
How can i convert following SQl that do full outer join on a table
FROM df AS df1 FULL OUTER JOIN df AS df2
ON df1.date = df2.date AND df1.product != df2.product
does
pd.merge(df1,df2, on="date , how="outer")
do the same? i guess not then how can i also tell pandas df1.product != df2.product
Upvotes: 0
Views: 102
Reputation: 827
Unfortunately, it's very hard to do non-equality join predicates in pandas. You'll have to first do your merge, then, assuming the result is stored in variable t
, filter you products: t[t['product_x'] != t['product_y']]
.
There are some packages (pandasql, duckdb) that let you query directly on dataframes, so that you can apply complex predicates, but I heard it can be rather slow. If your dataframe is of an intermediate size (fits comfortably in memory) I guess the first option is the simplest.
Upvotes: 1