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?

2
  • In what way does df[df['A'].str.contains("t")] (from that question) not work?? Commented May 16, 2013 at 6: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. Commented May 16, 2013 at 9:02

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.