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
Post a Comment