Here is my dataframe , I need to create a new column based on the timehour which the row value be like (morning, afternoon, evening, night)
Here is my code
if ((prods['hour'] < 4) & (prods['hour'] > 8 )):
prods['session'] = 'Early Morning'
elif ((prods['hour'] < 8) & (prods['hour'] > 12 )):
prods['session'] = 'Morning'
elif ((prods['hour'] < 12) & (prods['hour'] > 16 )):
prods['session'] = 'Noon'
elif ((prods['hour'] < 16) & (prods['hour'] > 20 )):
prods['session'] = 'Eve'
elif ((prods['hour'] < 20) & (prods['hour'] > 24 )):
prods['session'] = 'Night'
elif ((prods['hour'] < 24) & (prods['hour'] > 4 )):
prods['session'] = 'Late Night'
Here is the error i got
ValueError Traceback (most recent call last) in ----> 1 if (prods['hour'] > 4 and prods['hour']< 8): 2 prods['session'] = 'Early Morning' 3 elif (prods['hour'] > 8 and prods['hour'] < 12): 4 prods['session'] = 'Morning' 5 elif (prods['hour'] > 12 and prods['hour'] < 16):
/anaconda3/lib/python3.7/site-packages/pandas/core/generic.py in nonzero(self) 1476 raise ValueError("The truth value of a {0} is ambiguous. " 1477 "Use a.empty, a.bool(), a.item(), a.any() or a.all()." -> 1478 .format(self.class.name)) 1479 1480 bool = nonzero
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Kindly help