Home > front end >  How to Ignore Case Cases
How to Ignore Case Cases

Time:10-05

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)

CodePudding user response:

case=False:

cond_list = [df["item_name"].str.contains(animal, case=False) 
             for animal in animal_list]

Or re.IGNORECASE.

  • Related