Get part of day (morning, afternoon, evening, night) in Python dataframe
问题 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'