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<
After some research, this is the simplest and most efficient implementation I could find.
prods['period'] = (prods['hour_int'].dt.hour % 24 + 4) // 4 prods['period'].replace({1: 'Late Night', 2: 'Early Morning', 3: 'Morning', 4: 'Noon', 5: 'Evening', 6: 'Night'}, inplace=True)
I hope this helps.