This is a dataset that captures the time and duration that a switch is turned on/off. The Input column is the input captured at that time, while the duration column is the duration the switch is in the on/off status.
Time Device Input Status Duration
0 16-11-2020 00:00:00 led1 off on 0.00
1 16-11-2020 15:24:00 led1 on off 924.20
2 16-11-2020 17:51:00 led1 off on 147.55
3 16-11-2020 19:25:00 led1 on off 93.70
4 17-11-2020 01:07:00 led1 off on 341.97
5 17-11-2020 18:45:00 led1 on off 1057.87
6 17-11-2020 20:02:00 led1 off on 77.60
7 17-11-2020 20:34:00 led1 on off 31.65
I can split the date and time into new columns (using the only way i know how)
for i in range(len(df)):
df['Date'] = [i for i in range(len(df))]
df['Hour'] = [i for i in range(len(df))]
for i in range(len(df)):
df['Date'][i] = df['Time'][i][:10]
df['Hour'][i] = df['Time'][i][11:]
and the dataframe will return this
Time Device InputStatusDuration Date Hour
0 16-11-2020 00:00:00 led1 off on 0.00 16-11-2020 00:00:00
1 16-11-2020 15:24:00 led1 on off 924.20 16-11-2020 15:24:00
2 16-11-2020 17:51:00 led1 off on 147.55 16-11-2020 17:51:00
3 16-11-2020 19:25:00 led1 on off 93.70 16-11-2020 19:25:00
4 17-11-2020 01:07:00 led1 off on 341.97 17-11-2020 01:07:00
5 17-11-2020 18:45:00 led1 on off 1057.87 17-11-2020 18:45:00
6 17-11-2020 20:02:00 led1 off on 77.60 17-11-2020 20:02:00
7 17-11-2020 20:34:00 led1 on off 31.65 17-11-2020 20:34:00
Now how do I proceed to append a new column called 'Total duration', which is the sum of the duration for rows with the same dates?