Pandas不具备过滤条件

2024-03-28 12:04:37 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在筛选上实现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

Tags: andstorelambdaidslenwithnottemplate