Is there a more efficient way to do the following? Ideally, by using only one if statement?
Suppose there is a dataframe with an "author" series, a "comedy" series (default = True), and a "horror" series (default = False). I want to search the author series for "stephen king" and "lovecraft" and in those cases change the value of "comedy" from True to False and change the value of "horror" from False to True.
for count,text in enumerate(df.loc[0:, "author"]):
if "stephen king" in str(text):
df.loc[count, "comedy"] = False
df.loc[count, "horror"] = True
continue
elif "lovecraft" in str(text):
df.loc[count, "comedy"] = False
df.loc[count, "horror"] = True
continue
When I try using str.contains(), I get the error "str' object has no attribute 'str'".