How I can implement not condition on the filtering
grouped = store_ids_with_visits.groupby(level=[0, 1, 2])
grouped.filter(lambda x: (len(x) == 1 and x['template_fk'] == exterior_template))
I want to get all entries that not answering on the condition
I tried doing:
grouped.filter(lambda x: ~(len(x) == 1 and x['template_fk'] == exterior_template))
But got following error:
filter function returned a int, but expected a scalar bool
IIUC, you can use isin
to check for bool conditions and take only the NOT(~)
values of the grouped dataframe:
df[~df.isin(grouped.filter(lambda x: (len(x) == 1 and x['template_fk'] == exterior_template)))]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With