I'm novoce to pandas. Need to calculate time for each person, for each location and drop rows without pair in dates col. My data looks like this:
Unit Name Location Date Time
0 K1 Somebody1 LOC1 2020-05-12 07:00
1 K1 Somebody1 LOC1 2020-05-12 20:10
2 K1 Somebody1 LOC1 2020-05-13 06:00
3 K1 Somebody1 LOC1 2020-05-13 20:00
4 K1 Somebody1 LOC1 2020-05-14 06:37
5 K1 Somebody1 LOC2 2020-05-15 07:00
6 K1 Somebody1 LOC2 2020-05-15 20:10
7 K1 Somebody1 LOC2 2020-05-16 06:00
8 K1 Somebody1 LOC2 2020-05-16 20:00
9 K1 Somebody1 LOC2 2020-05-17 06:37
10 K1 Somebody2 LOC2 2020-05-13 07:00
11 K1 Somebody2 LOC2 2020-05-14 10:10
12 K1 Somebody2 LOC2 2020-05-14 16:50
13 K1 Somebody2 LOC2 2020-05-15 05:36
14 K1 Somebody3 LOC1 2020-05-13 07:00
15 K1 Somebody3 LOC1 2020-05-14 10:10
16 K1 Somebody3 LOC1 2020-05-14 16:50
17 K1 Somebody3 LOC1 2020-05-15 05:36
I only menaged to convert time to datetime object by
df['Time'] = df['Time'].apply(lambda x: datetime.strptime(x,'%H:%M').time())
Tried using pivot tables, grouping by, for loops and I'm out of ideas. I wanted output to look like that:
LOC1
Somebody1 2020-05-12 13h 10m
2020-05-13 14h 00m
TOTAL 27h 00m
Somebody2 date hours
date hours
TOTAL sum for somebody2
Somebody3 date hours
date hours
TOTAL sum for somebody3
LOC2
Somebody1 date hours
date hours
TOTAL sum for somebody1
Somebody2 date hours
date hours
TOTAL sum for somebody2
or something similar