select inverse with conditions pandas 1

select inverse with conditions pandas

In [411]:
df_a[~((df_a['id'].isin(values1)) & (df_a['car'].isin(values2)))]
#     ^                                                        ^
Out[411]:
   id    car
3  s4  mazda
5  s5    bmw
6  s4   audi

Here is what the above code is Doing:
1. df_a['id'].isin(values1) returns a boolean series of True and False values.
2. df_a['car'].isin(values2) returns a boolean series of True and False values.
3. & is the bitwise AND operator. It returns a boolean series of True and False values.
4. ~ is the bitwise NOT operator. It returns a boolean series of True and False values.
5. df_a[...] returns a dataframe of rows where the boolean series is True.

Similar Posts