選項1
假設沒有其他已存在的pir
df[df.replace(['#', '*', '**'], 'pir').eq('pir').any(1)]
code tag number floor note
1 1111 * ** 34 no
3 3677 # 900 11 no
4 9897 10 134 * no
5 # # 566 11 no
選項2
令人討厭的numpy
broa dcasting。快在第一,但平方縮放
df[(df.values[None, :] == np.array(['*', '**', '#'])[:, None, None]).any(0).any(1)]
code tag number floor note
1 1111 * ** 34 no
3 3677 # 900 11 no
4 9897 10 134 * no
5 # # 566 11 no
選項3
較少令人厭惡np.in1d
df[np.in1d(df.values, ['*', '**', '#']).reshape(df.shape).any(1)]
code tag number floor note
1 1111 * ** 34 no
3 3677 # 900 11 no
4 9897 10 134 * no
5 # # 566 11 no
選項4
多年來與頂端
df[list(
map(bool,
map({'*', '**', '#'}.intersection,
map(set,
zip(*(df[c].values.tolist() for c in df)))))
)]
code tag number floor note
1 1111 * ** 34 no
3 3677 # 900 11 no
4 9897 10 134 * no
5 # # 566 11 no
哦,快點。Brb撤消一些投票。 –