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)
Answer from Bill the Lizard on Stack OverflowSeries.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)
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)]
If you don't want to use str.lower(), you can use a regular expression:
import re
if re.search('mandy', 'Mandy Pande', re.IGNORECASE):
# Is True
You are looking for the .lower() method:
string1 = "hi"
string2 = "HI"
if string1.lower() == string2.lower():
print("Equals!")
else:
print("Different!")
Btw, There's another post here. Try looking at this.
python - Using Pandas str.contains using Case insensitive - Stack Overflow
Case insensitive using startswith
Need help with case insensitive list comparison in Python
Case insensitive .contains() Sqlalchemy ?
I'm trying to do a quick database search in python using pandas.
data = pd.read_excel(open('Stockroom_Inventory_May_4_2020.xlsx', 'rb'),sheet_name='Chemical')
#This works fine for case insensitive search
data.loc[data['Item Name *'].str.contains('Ferro', case = False)][['Item Name *','Location','Sub-location','Location Details']]
#Can't use case = False with startswith
data.loc[data['Item Name *'].str.startswith('Ferro')][['Item Name *','Location','Sub-location','Location Details']]
Is there a way to get around this, even making everything from the excel file lowercase would be fine.
Thanks for your help