Edamame
Edamame

Reputation: 25366

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

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!

Upvotes: 4

Views: 6842

Answers (2)

Joe T. Boka
Joe T. Boka

Reputation: 6585

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)]

Upvotes: 5

bzimor
bzimor

Reputation: 1628

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

Upvotes: 1

Related Questions