Question: 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?

Answer: 
Here's a way you can do:

```
df[df.applymap(lambda x: x == 'A').any(1)]

  col1 col2 col3 col4
0    A    W    Z    C
4    M    A    V    C
5    D    O    X    A
7    Q    V    R    A

```

For multiple cases, you can do like `A`, `B`:

```
df[df.applymap(lambda x: x in ['A','B']).any(1)]

```
We could use [`DataFrame.stack`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.stack.html) + [`Series.unstack`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.unstack.html) with [`DataFrame.any`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.any.html)

```
df[df.stack(dropna=False).str.contains('A').unstack().any(axis=1)]

```

**or better solution suggested by @Alollz**

```
df[df.stack().str.contains('A').any(level=0)]

```

**Output**

```
  col1 col2 col3 col4
0    A    W    Z    C
4    M    A    V    C
5    D    O    X    A
7    Q    V    R    A

```

**UPDATE**

To check several characters use `join`

```
df[df.stack().str.contains('|'.join(['A','B'])).any(level=0)]

  col1 col2 col3 col4
0    A    W    Z    C
3    B    C    B    C
4    M    A    V    C
5    D    O    X    A
7    Q    V    R    A

```