4

I have the following code to check if the value of certain column contains the given string:

my_df[my_df.name.str.contains('Mike')]

However, when I tried to make it work for all letter cases like:

my_df[my_df.name.str.lower.contains('mike')]

I got the following error:

AttributeError: 'function' object has no attribute 'contains'

What should be the correct way to call the lower() function, so I can make sure the match is case insensitive? Thanks!

2 Answers 2

5

You can use the boolean parameter case. It's set to True by default, which is case sensitive. Thus, you should set it to False. Pandas Documentation

my_df[my_df.name.str.contains('Mike', case=False)]
Sign up to request clarification or add additional context in comments.

Comments

1

Use this:

my_df[my_df.name.str.contains('Mike', flags=re.IGNORECASE)]

Source: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.contains.html

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.