Samsonite Manly
Samsonite Manly

Reputation: 659

pandas "case insensitive" in a string or "case ignore"

Here is the code that works for lowercase and returns only "apple":

df2 = df1['company_name'].str.contains("apple", na=False)

I need this to find "apple", "APPLE", "Apple", etc. Something like:

df2 = df1['company_name'].str.contains.caseignore("apple", na=False)

is there such a function anywhere?

Upvotes: 46

Views: 59881

Answers (2)

Bharath manda
Bharath manda

Reputation: 37

If you want to do the exact match and with strip the search on both sides with case ignore,

df[df['Asset Name'].str.strip().str.match('searchstring'.strip(), case=False)]

Upvotes: 2

Bill the Lizard
Bill the Lizard

Reputation: 405765

Series.str.contains has a case parameter that is True by default. Set it to False to do a case insensitive match.

df2 = df1['company_name'].str.contains("apple", na=False, case=False)

Upvotes: 101

Related Questions