Nig*_*ker 2 python dataframe pandas
我怎么能在过滤上实现不条件
grouped = store_ids_with_visits.groupby(level=[0, 1, 2])
grouped.filter(lambda x: (len(x) == 1 and x['template_fk'] == exterior_template))
Run Code Online (Sandbox Code Playgroud)
我希望得到所有没有回答条件的条目
我试过做:
grouped.filter(lambda x: ~(len(x) == 1 and x['template_fk'] == exterior_template))
Run Code Online (Sandbox Code Playgroud)
但得到以下错误:
filter function returned a int, but expected a scalar bool
Run Code Online (Sandbox Code Playgroud)
IIUC,您可以使用isin
检查bool条件并仅NOT(~)
采用分组数据帧的值:
df[~df.isin(grouped.filter(lambda x: (len(x) == 1 and x['template_fk'] == exterior_template)))]
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6425 次 |
最近记录: |