I'm using the code below to create a new column [covid_ind] which should be 1 when an existing column [calendar_yr] is either 2020 or 2021. And 0 otherwise. I don't know why I'm getting the error.
# Flag Covid years
covid_yrs = [2020, 2021]
df.loc[df['calendar_yr'] in covid_yrs, 'COVID_IND'] = 1
df.loc[df['calendar_yr'] not in covid_yrs, 'COVID_IND'] = 0
The following error message is coming on the 3rd line above.
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().