I have a DataFrame
like this:
Name first_seen last_seen
0 Random guy 1 5/22/2016 18:12 5/22/2016 18:15
1 Random guy 2 5/22/2016 12:03 5/22/2016 12:03
2 Random guy 3 5/22/2016 21:06 5/22/2016 21:06
3 Random guy 4 5/22/2016 16:20 5/22/2016 16:20
4 Random guy 5 5/22/2016 14:46 5/22/2016 14:46
Now I have to add a column
named Visit_period
which takes one of 4 values [morning,afternoon,evening,night]
when maximum time spent by that person (row
) fell into:
- morning: 08:00 to 12:00 hrs
- afternoon: 12:00 to 16:00 hrs
- evening: 16:00 to 20:00 hrs
- night: 20:00 to 24:00 hrs
so for above five row out put will be something like this.
visit_period
evening
afternoon
night
evening
afternoon
I have mentioned maximum time spent because, it may happen that some person's first_seen
is at 14:30 and last_seen
is 16:21. I would like to assign the value afternoon
as he spent 30 mins in afternoon slab and 21 in evening slab.
I am using python 2.7.