I need to remove from my dataframe the rows that in a column matches the string from a list.
I used wo_list = df[~df.Match.isin(mylist)]
The problem is that some strings have a capital first letter in the list but not in my df.
Thanks for any help.
Answer
One idea is convert both – column and list to lowercase:
mylist = ['Yui','Adf'] df = pd.DataFrame({'Match':['adf','ert','yui']}) wo_list = df[~df.Match.str.lower().isin([str(x).lower() for x in mylist])] print (wo_list) Match 1 ert
Or you can use Series.str.capitalize
for column for match list:
mylist = ['Yui','Adf'] df = pd.DataFrame({'Match':['adf','ert','yui']}) wo_list = df[~df.Match.str.capitalize().isin(mylist)] print (wo_list) Match 1 ert