python - Pandas converting String object to lower case and checking for string -


i have below code

import pandas pd private = pd.read_excel("file.xlsx","pri") public = pd.read_excel("file.xlsx","pub") private["ish"] = private.holidayname.str.lower().contains("holiday|recess") public["ish"] = public.holidayname.str.lower().contains("holiday|recess") 

i following error:

attributeerror: 'series' object has no attribute 'contains' 

is there anyway convert 'holidayname' column lower case , check regular expression ("holiday|recess")using .contains in 1 step?

any appreciated

private["ish"] = private.holidayname.str.contains("(?i)holiday|recess") 

the (?i) in regex pattern tells re module ignore case.


the reason why getting error because series object not have contains method; instead series.str attribute has contains method. avoid error with:

private["ish"] = private.holidayname.str.lower().str.contains("holiday|recess") 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -