Question: I have a pandas dataframe whose entries are all strings:

```
   A     B      C
1 apple  banana pear
2 pear   pear   apple
3 banana pear   pear
4 apple  apple  pear

```

etc. I want to select all the rows that contain a certain string, say, 'banana'. I don't know which column it will appear in each time. Of course, I can write a for loop and iterate over all rows. But is there an easier or faster way to do this?

Answer: 
For single search value 

```
df[df.values  == "banana"]

```

or 

```
 df[df.isin(['banana'])]

```

For multiple search terms: 

```
  df[(df.values  == "banana")|(df.values  == "apple" ) ]

```

or

```
df[df.isin(['banana', "apple"])]

  #         A       B      C
  #  1   apple  banana    NaN
  #  2     NaN     NaN  apple
  #  3  banana     NaN    NaN
  #  4   apple   apple    NaN

```

From Divakar: lines with both are returned. 

```
select_rows(df,['apple','banana'])

 #         A       B     C
 #   0  apple  banana  pear

```
If you want all the rows of `df` that contain **any** of the values in `values`, use:

```py
df[df.isin(values).any(1)]

```

---

Example:

```
In [2]: df                                                                                                                       
Out[2]: 
   0  1  2
0  7  4  9
1  8  2  7
2  1  9  7
3  3  8  5
4  5  1  1

In [3]: df[df.isin({1, 9, 123}).any(1)]                                                                                          
Out[3]: 
   0  1  2
0  7  4  9
2  1  9  7
4  5  1  1

```