3

pool is a dataframe, and one of the columns is "Name" If key == 'Bob', then this line correctly gives me all the rows where Name=='Bob':

keyrows = pool[key == pool.Name]

I instead want to get all the rows that match 'Bob', like "Bob Jones" and "Bob Marley", etc.

So I changed '==' to 'in', but it doesn't work as I expected:

keyrows = pool[key in pool.Name]

I get KeyError: False

Any help would be much appreciated.

1

1 Answer 1

6

@behzad.nouri gave me the solution:

keyrows = pool[pool.Name.str.contains(key)]

does exactly what I want.

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.