I have a pandas dataframe like
| Status | Time Stamp |
|---|---|
| Passing | 2021-11-25 15:15:36 |
| Failing | 2021-11-25 00:46:23 |
| Failing | 2021-11-25 00:16:03 |
| Failing | 2021-11-24 23:45:08 |
| Passing | 2021-11-25 15:15:13 |
| Failing | 2021-11-25 00:46:47 |
| Failing | 2021-11-25 00:16:09 |
| Failing | 2021-11-24 23:44:59 |
I need to get the time of the first passing event to the first instance of when it failed for that sequence. So the difference row 0 and row 3, and add it to a new column.
Then I need it to calculate the next sequence and add it to the value in the new column.
So the difference between row 4 and row 7 and add the difference to the previous time so I get the total time it was failing.
This is what the df should look like at the end
| Status | Time Stamp | Downtime | Total Downtime |
|---|---|---|---|
| Passing | 2021-11-25 15:15:36 | 15:30:38 | 31:00:52 |
| Failing | 2021-11-25 00:46:23 | 15:30:38 | 31:00:52 |
| Failing | 2021-11-25 00:16:03 | 15:30:38 | 31:00:52 |
| Failing | 2021-11-24 23:45:08 | 15:30:38 | 31:00:52 |
| Passing | 2021-11-25 15:15:13 | 15:30:14 | 31:00:52 |
| Failing | 2021-11-25 00:46:47 | 15:30:14 | 31:00:52 |
| Failing | 2021-11-25 00:16:09 | 15:30:14 | 31:00:52 |
| Failing | 2021-11-24 23:44:59 | 15:30:14 | 31:00:52 |
Note that this is example data and the index's of passing and failing events are at different index each time.
Here is my code
import pandas as pd
data = {'Status': ['Passing','Failing','Failing','Failing','Passing','Failing','Failing','Failing'],
'TimeStamp': ['2021-11-25 15:15:36','2021-11-25 00:46:23','2021-11-25 00:16:03','2021-11-24 23:45:08','2021-11-25 15:15:13','2021-11-25 00:46:47','2021-11-25 00:16:09','2021-11-24 23:44:59']}
df = pd.DataFrame(data)
I'm self taught in Python and pandas and have no idea how to achieve what I need. Any help would be appreciated.