赞
踩
你需要:fil_1 = test['col_a'].isin(['abc','def','ghi'])
fil_2 = test['col_b'].isin(['yes'])
fil_3 = test['col_c'].isin(['a'])
或者test.isin({'col_a': ['abc','def','ghi'],
'col_b': ['yes'],
'col_c' :['a']}).all(axis = 1)df_filtered = test[fil_1 & fil_2 & fil_3]
print(df_filtered)
col_a col_b col_c
0 abc yes a
2 abc yes a
4 def yes a
6 def yes a
8 ghi yes a
10 ghi yes a
或逻辑|fil = test.isin({'col_a': ['abc','def','ghi'],'col_b': ['yes'],'col_c' :['a']})
df_filtered = df[fil]
print(df_filtered)
col_a col_b col_c
0 abc yes a
1 abc NaN NaN
2 abc yes a
3 def NaN NaN
4 def yes a
5 def NaN NaN
6 def yes a
7 def NaN NaN
8 ghi yes a
9 ghi NaN NaN
10 ghi yes adf_filtered = df[fil.all(axis = 1)]
print(df_filtered)
col_a col_b col_c
0 abc yes a
2 abc yes a
4 def yes a
6 def yes a
8 ghi yes a
10 ghi yes a
细节print(fil)
col_a col_b col_c
0 True True True
1 True False False
2 True True True
3 True False False
4 True True True
5 True False False
6 True True True
7 True False False
8 True True True
9 True False False
10 True True Trueprint(test.isin({'col_a': ['abc','def','ghi']}))
col_a col_b col_c
0 True False False
1 True False False
2 True False False
3 True False False
4 True False False
5 True False False
6 True False False
7 True False False
8 True False False
9 True False False
10 True False False
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。