I have 1 pandas data-frame with date and time. I want to add 1 more column called session, with values morning afternoon, evening, night.
Time
2016-07
Use pd.cut
to create bins for your session labels.
df.assign(session=pd.cut(df.Time.dt.hour,[0,6,12,18,24],labels=['Night','Morning','Afternoon','Evening']))
Output:
Time session
0 2016-07-10 01:18:00 Night
1 2016-07-10 11:21:00 Morning
2 2016-07-10 17:29:00 Afternoon
3 2016-07-10 21:43:00 Evening