I have dataframe like this
data = {
"timeStamp": [06:00:00, 06:03:00, 06:10:00, 06:30:00, 06:32:00, 06:02:00, 06:05:00, 06:06:00, 06:55:00, 06:00:00, 06:01:00, 06:20:00, 07:00:00],
"Event": [A, A, A, A, A, B, B, B, B, C, C, C, D]
}
df = pd.DataFrame(data)
I need to know shortest intervals that contain 3 or more rows by each group.
In given example we see:
- that during event “A” shortest interval with 3 rows is 10 minutes (from 06:00:00 to 06:10:00)
- during event “B” shortest interval with 3 rows is 4 minutes (from 06:02:00 to 06:06:00)
- during event “C” shortest interval with 3 rows is 20 minutes (from 06:00:00 to 06:20:00)
- there are now such intervals during event “D”
Desired output looks like
Event | Interval |
---|---|
A | 00:10:00 |
B | 00:04:00 |
C | 00:20:00 |
D | NA |
…
etc
Is there any elegant way to do this?
4