2016-07-31 182 views
1

我怎樣才能實現對過濾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 
+0

試着用'not'替換'〜'(按位NOT運算符) - 例如'not(len(x)...' – jedwards

+0

@jedwards用這個我得到'一個系列的真值不明確' –

+0

在你的數組中使用'any'或'all'內建函數 –

回答

1

IIUC,您可以使用isin檢查布爾條件,只需要分組數據框的NOT(~)值:

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