如何在过滤上实现not条件
grouped = store_ids_with_visits.groupby(level=[0, 1, 2])
grouped.filter(lambda x: (len(x) == 1 and x['template_fk'] == exterior_template))我想要获取所有不符合条件的条目
我试着这样做:
grouped.filter(lambda x: ~(len(x) == 1 and x['template_fk'] == exterior_template))但得到以下错误:
filter function returned a int, but expected a scalar bool发布于 2016-07-31 16:22:01
IIUC,您可以使用isin检查布尔条件,并仅获取分组数据帧的NOT(~)值:
df[~df.isin(grouped.filter(lambda x: (len(x) == 1 and x['template_fk'] == exterior_template)))]https://stackoverflow.com/questions/38681802
复制相似问题