
Longest incident per service
mediumLongest incident per service
PagerDuty Pandas Interview Question
A PagerDuty customer review opens with the single worst incident of the period, not the average, because the average is held down by the pages that resolved in ten minutes while the escalation everybody remembers ran for hours.
Using the incidents DataFrame, find each service, the incident_id of its longest incident, and how long that one took in hours as hours_open, rounded to 2 decimal places. Assign the answer to result.
Asked of
- Data Analyst
- Analytics Engineer
- Data Engineer
- Data Scientist
incidentsDataFrame20 rows
| Column Name | Type |
|---|---|
| incident_id | int64 |
| service | str |
| started_at | str |
| resolved_at | str |
| severity | str |
incidentsExample Input
| incident_id | service | started_at | resolved_at | severity |
|---|---|---|---|---|
| 6001 | checkout-api | 2024-10-01 02:10:00 | 2024-10-01 03:40:00 | SEV2 |
| 6002 | checkout-api | 2024-10-01 03:05:00 | 2024-10-01 04:25:00 | SEV3 |
| 6003 | checkout-api | 2024-10-01 06:00:00 | 2024-10-01 06:45:00 | SEV1 |
| 6004 | checkout-api | 2024-10-02 09:30:00 | 2024-10-02 10:15:00 | SEV3 |
| 6005 | checkout-api | 2024-10-02 10:10:00 | 2024-10-02 11:50:00 | SEV2 |
| 6011 | billing-worker | 2024-10-01 12:00:00 | 2024-10-01 12:30:00 | SEV3 |
| 6012 | billing-worker | 2024-10-01 12:30:00 | 2024-10-01 13:15:00 | SEV2 |
| 6013 | billing-worker | 2024-10-01 15:40:00 | 2024-10-01 16:55:00 | SEV1 |
| 6014 | billing-worker | 2024-10-03 08:05:00 | 2024-10-03 08:35:00 | SEV3 |
| 6020 | checkout-api | 2024-10-04 07:00:00 | 2024-10-04 07:25:00 | SEV3 |
Example Output
| service | incident_id | hours_open |
|---|---|---|
| billing-worker | 6013 | 1.25 |
| checkout-api | 6005 | 1.67 |
Explanation
In the example the billing worker's longest incident is 6013, which ran an hour and a quarter. The checkout service has six incidents and 6005 is the longest at 1.67 hours, even though two of the others started earlier in the day.
The example above is a small slice of the data. Your code runs against the full DataFrames.
Company
PagerDuty
Difficulty
medium
Topic
ranking
Language
Pandas
Your code
Loading Python in the background. You can start writing.