我认为需要列表理解来创建mask
然后np.logical_and.reduce https://stackoverflow.com/q/20528328/2901002用于减少和最后过滤boolean indexing http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing:
filterfieldList = ['A','B','E']
filterValuesList = ['Project 1', 'Org_1', 'Unable to Login']
tups = zip(filterfieldList, filterValuesList)
df_result = df[np.logical_and.reduce([(df[i] == j) for i, j in tups])]
print (df_result)
A B C D E
1 Project 1 Org_1 Directory MSTR Unable to Login
4 Project 1 Org_1 Directory MSTR Unable to Login
EDIT:
如果需要每行组合多个过滤器:
filterfieldList = ['A','B','E', 'E']
filterValuesList = ['Project 1', 'Org_1', 'Unable to Login', 'Configuration']
f = pd.DataFrame({'field': filterfieldList, 'val':filterValuesList})
f = f.groupby('field')['val'].apply(list)
print (f)
field
A [Project 1]
B [Org_1]
E [Unable to Login, Configuration]
Name: val, dtype: object
df_result = df[np.logical_and.reduce([(df[i].isin(j)) for i, j in f.items()])]
print (df_result)
A B C D E
0 Project 1 Org_1 Directory MSTR Configuration
1 Project 1 Org_1 Directory MSTR Unable to Login
2 Project 1 Org_1 Desktop Software MSTR Configuration
4 Project 1 Org_1 Directory MSTR Unable to Login