I have a sample pandas dataframe df:
col1 col2 col3 col4
0 a 1.0 2.0 3
1 b NaN NaN 6
2 c NaN 8.0 9
3 d NaN 11.0 12
4 e 13.0 14.0 15
5 f 17.0 18.0 19
6 g 21.0 22.0 23
and a second one df1:
col1 col2 col3 col4
0 a 1.0 2.0 3
4 e 13.0 14.0 15
5 f 17.0 18.0 19
6 g 21.0 22.0 23
I want to get the subset of df that does not overlaps with df1. In effect I am looking for the equivalent of the EXCEPT operand in SQL.
I used the subtract() function -- but this was clearly wrong, as the subtract performs elementwise numerical subtraction. So I got an error message:
TypeError: unsupported operand type(s) for -: 'str' and 'str'
So the question is: What is the equivalent of EXCEPT in SQL for Pandas?
I think you need
set_index
of all string columns first:Or:
EDIT by edited question: