'The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). in conditional in python [duplicate]
I tried to do
if (df1['Year']>5)&(df1['TotalMntProducts']>2000):
print(1)
else:
print(0)
this in order to make a new column by condition and got ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
what should I do?
Solution 1:[1]
Are these Pandas DataFrames?
df1['new_column'] = df1.apply(lambda row: 1 if row.Year > 5 and row.TotalMntProducts > 2000 else 0, axis=1)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | BeRT2me |
