Q:

Searching for String Value in Pandas

I am trying to search values in a Pandas dataframe.
This is how my DF looks like:
                                                       0          1            2   \
0                                                 NaN        NaN          NaN   
1              CITI Pass-T...                     NaN        NaN   
2                                                 NaN        NaN          NaN   
3              Certificateholder Distribution Summary        NaN          NaN   
4                                               Class      CUSIP  Record Date   
5                                                 A-1  25151EAA1   12/30/2016   
6                                                 A-2  25151EAB9   12/30/2016   
7                                                 A-3  25151EAC7   12/30/2016   
8                                                 A-4  25151EAD5   12/30/2016   
9                                                A-5A  25151EAE3   12/30/2016   
10                                               A-5B  25151EAF0   12/30/2016   
11                                                A-6  25151EAG8   12/30/2016   
12                                                A-7  25151EAH6   12/30/2016   
13                                                A-8  25151EAJ2   01/24/2017   
14                                                M-1  25151EAK9   12/30/2016   
15                                                M-2  25151EAL7   12/30/2016   
16                                                M-3  25151EAM5   12/30/2016   
17                                                M-4  25151EAN3   12/30/2016   
18                                                M-5  25151EAP8   12/30/2016   
19                                                M-6  25151EAQ6   12/30/2016   
20                                                M-7  25151EAR4   12/30/2016   
21                                                M-8  25151EAS2   12/30/2016   
22                                                M-9  25151EAT0   12/30/2016   
23                                               M-10  25151EAU7   12/30/2016   
24                                               M-11  25151EAV5   12/30/2016   
25                                                  P  25151EAX1   12/30/2016   
26                                                 CE  25151EAW3   12/30/2016   
27                                                  R  25151EAY9   12/30/2016   
28                                             Totals        NaN          NaN   
29  This report is compiled by me, N...                      NaN          NaN   
30  All Record Dates are based upon the governing ...        NaN          NaN   
31                                                NaN        NaN          NaN  

So you see, there are no real column headers.
Now I want for example search for the value A-1.
This is what I did:
for col in df:
    print col
    print df[df[col].str.contains("A-1", na=False)]

This actually gives me my desired result:
    0          1           2     3           4        5          6         7   \
5  A-1  25151EAA1  12/30/2016  6.25  7218381.58  25379.0  143237.93  71982.98   

           8          9           10  11  12  13  14  
5  7003160.66  168616.93  6169381.87 NaN NaN NaN NaN  

But then I get the following error:
AttributeError: Can only use .str accessor with string values, which use np.object_ dtype in pandas

Does someone has any idea what I am doing wrong?

A:

I'll give it a go, you can check if column is not empty like this:
for col in df:
    if not df[col].empty:
        print col
        print df[df[col].str.contains("A-1", na=False)]

