GENERAL QUESTION
I was wondering if there exists a Python opposite to __contains__
(i.e., something like __notcontains__
).
MY EXAMPLE
I need it for the following piece of code:
df_1 = df[(df.id1 != id1_array) | (df.id2.apply(id2_array.__contains__)]
df_2 = df[(df.id1 == id1_array) & (df.id2.apply(id2_array.__notcontains__)]
In other words, in df1
I want only observations for which id1
is not in id1_array1
or id2
is in id2_array
, while for df2
I want only observations for which id1
is in id1_array
and id2
is not in id2_array
.
Who can help me out here? Thanks in advance!
not in
?something.__contains__(some_other_thing) is False
?df_1 = df[(df.id1 != id1_array) | (~df.id2.isin(id2_array)]