Issue
How would I go about ignoring the case sensitivity in this code below? I have a list that's looking up a substring of a dataframe but I'm finding that it's case sensitive.
import pandas as pd
import numpy
data = ['Condor',
'Marmot',
'Bear',
'Condor a',
'Marmotb',
'Bearxyz']
df = pd.DataFrame(data, columns=["item_name"])
animal_list = ['Condor',
'Marmot',
'Bear',
'Pika',
'Rat',
'Racoon',
'Opossum']
cond_list = [df["item_name"].str.contains(animal)
for animal in animal_list]
df["animal"] = np.select(cond_list, animal_list)
Solution
case=False
:
cond_list = [df["item_name"].str.contains(animal, case=False)
for animal in animal_list]
Or re.IGNORECASE
.
Answered By - U12-Forward
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.