>>> df['E']=['a','a','c','b']
>>> df
A B C D E
0 -0.018330 2.093506 -0.086293 -2.150479 a
1 0.104931 -0.271810 -0.054599 0.361612 a
2 0.590216 0.218049 0.157213 0.643540 c
3 -0.254449 -0.593278 -0.150455 -0.244485 b
>>> df.E.isin(['a','c'])
0 True
1 True
2 True
3 False
Name: E, dtype: bool
>>> df.isin(['b','c'])#整个df也同样适用
A B C D E
0 False False False False False
1 False False False False False
2 False False False False True
3 False False False False True
#应用,筛选出含有与目标元素含有相同元素的行
>>> df[df.E.isin(['a','c'])]
A B C D E
0 -0.018330 2.093506 -0.086293 -2.150479 a
1 0.104931 -0.271810 -0.054599 0.361612 a
2 0.590216 0.218049 0.157213 0.643540 c
>>>
类似的可以筛选出Train与Test数据集中含有相同Column的列数据
labels = test_labels[test_labels.isin(df_train.columns)]