您也可以使用。应用:
df.apply(lambda row: row[df['B'].isin(['one','three'])])
它实际上是按行运行的(即,将函数应用于每一行)。
输出为
A B C D 0 foo one 0 0 1 bar one 1 2 3 bar three 3 6 6 foo one 6 12 7 foo three 7 14
结果与@unutbu提到的相同
df[[df['B'].isin(['one','three'])]]