'Time Buckets to group the data in Python
I would like to have a certain time buckets and then find the difference of each time bucket to analyse.
For example,
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': 'A-1 A-1 A-1 A-1 A-1 A-1'.split(),
'Date':'23.10.2021 23.10.2021 23.10.2021 23.10.2021 23.10.2021 23.10.2021'.split(),
'Time': '06:05:31 06:11:13 06:19:22 06:25:03 06:33:12 06:44:05'.split(),
'Cumulative': '12 17 19 23 29 38'.split()})
print(df)
out:
A Date Time Cumulative
0 A-1 23.10.2021 06:05:31 12
1 A-1 23.10.2021 06:11:13 17
2 A-1 23.10.2021 06:19:22 19
3 A-1 23.10.2021 06:25:03 23
4 A-1 23.10.2021 06:33:12 29
5 A-1 23.10.2021 06:44:05 38
What I'd like to have is ceiling the hours by 15 mins intervals and find the difference of each, 1st Step:
A Date Time Cumulative TimeBuckets
0 A-1 23.10.2021 06:05:31 12 06:15:00
1 A-1 23.10.2021 06:11:13 17 06:15:00
2 A-1 23.10.2021 06:19:22 19 06:30:00
3 A-1 23.10.2021 06:25:03 23 06:30:00
4 A-1 23.10.2021 06:33:12 29 06:45:00
5 A-1 23.10.2021 06:44:05 38 06:45:00
and in final stage as a different dataframe, difference of each minimum and maximum value for each time bucket would be written:
A Diff TimeBuckets
0 A-1 5 06:15:00
1 A-1 4 06:30:00
2 A-1 8 06:45:00
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|