I have a dataframe like this:
col1 col2 col3 col4
A W Z C
F W P F
E P Y C
B C B C
M A V C
D O X A
Y L Y D
Q V R A
I want to filter if multiple columns have a certain value. For instance I want to filter the rows that contain A. As a result it should be:
col1 col2 col3 col4
A W Z C
M A V C
D O X A
Q V R A
Since it is just a small representation of a large dataset, I cannot go with
df[(df['col1'].str.contains('A')) | (df['col2'].str.contains('A')) | (df['col3'].str.contains('A')) |
(df['col4'].str.contains('A'))]
Is there any other way?