Reputation: 279
I have a log of people entering and leaving the room.
Sample Data:
data = {'Person': ['A','B','C'],
'Enter': ['11:14:22','11:15:46','11:16:22'],
'Leave': ['11:16:40','11:18:21','11:18:22'],
}
df = pd.DataFrame (data, columns = ['Person','Enter','Leave'])
Into:
11:13 - 0 (Empty)
11:14 - 1 (Person A only)
11:15 - 2 (A + B)
11:16 - 3 (C Enters, plus A+B)
11:17 - 2 (A left, only B + C in Room)
11:18 - 2 (Same)
11:19 - 0 (Empty)
I think I can plot by box chart (Part 2), but I am struggling to determine (or transform time-range) into how many people in the room by the minute. Any suggestions would be appreciated.
Upvotes: 0
Views: 168
Reputation: 279
Essentially, I've done the following:
` def round_minute(atime):
return time(atime.hour,atime.minute-1,0), time(atime.hour,atime.minute+1,0)
def headcounter(dff):
dur = (datetime.combine(datetime.today(), dff['Leave_Time'].max()) - datetime.combine(datetime.today(), dff['Join_Time'].min())).total_seconds()
time_in_session = {}
for i in range(0,math.ceil(dur/60)+3):
_ = (datetime.combine(datetime.today(), round_minute(dff['Join_Time'].min())[0]) + timedelta(minutes = i)).time()
counter = 0
for z in range(0,dff.shape[0]-1):
if (dff['Join_Time'][z] < _ and _ < dff['Leave_Time'][z]):
counter +=1
time_in_session[_] = counter
return time_in_session
Upvotes: 1