ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

Dear experts,

Please help me to solve below error:
“ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().”

Here is my code:
if df[‘new_cases’] > 1000:
df[‘Remarks’] = “Alarming Situation”
else:
df[‘Remarks’] = “Moderate”

You can’t add a column like that.

You need to use list comprehension here:

df["column_name"] = ["condition true" if x > 1000 else "condition false" for x in df["cases"]]
1 Like

Thanks, code works for me, I did it an other ways, please see blow:

df.loc[df[‘new_cases’] > 1000, ‘Status’] = ‘Alarming’
df.loc[df[‘new_cases’] < 1000, ‘Status’] = ‘Moderate’