2

I'm trying to figure out how to print a row given a known entry in a column within my data frame much like this question. However, this wasn't working for my DataFrame.

In [10]: df
Out[10:
   A   B   C   D
0  a   b   c   d
1  t   f   h   e
2  j   r   y   k

In [11]: df[df['A'].str.contains('t')]

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-618e00d5bb36> in <module>()
----> 1 df[df['A'].str.contains('t')]

AttributeError: 'Series' object has no attribute 'str'

Just to try and clarify my goal, say I know 't' is in my DataFrame somewhere and I also know it resides within column A, is there a search option that will print out the entire row it is located within?

Why am I getting this error?

Community
  • 1
  • 1
Matt
  • 3,229
  • 5
  • 32
  • 61
  • In what way does `df[df['A'].str.contains("t")]` (from that question) not work?? – Andy Hayden May 16 '13 at 06:32
  • Comments on the deleted answer showed that this wasn't working since the OP was using an old version of pandas (0.8), and an upgrade (to 0.11) fixed it. – Andy Hayden May 16 '13 at 09:02

1 Answers1

1

Vectorized string methods were introduced in pandas 0.9 (so it isn't available as a Series method in version you're using: 0.8). Refresh your pandas to the latest stable version for the latest and greatest features.

Andy Hayden
  • 291,328
  • 80
  • 565
  • 500