大熊猫没有过滤条件

时间:2016-07-31 07:34:15

标签: python pandas dataframe

我如何在过滤上实现不条件

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

1 个答案:

答案 0 :(得分:6)

IIUC,您可以使用isin检查布尔条件,并仅采用分组数据框的NOT(~)值:

 df[~df.isin(grouped.filter(lambda x: (len(x) == 1 and x['template_fk'] == exterior_template)))]
相关问题