
Hours lost by day
hardHours lost by day
PagerDuty Pandas Interview Question
A service that loses an hour every day and a service that loses four hours in one bad afternoon need different fixes: the first is rotting, the second had an accident. A weekly total cannot tell them apart, so PagerDuty's reliability review tracks the hours each service lost on each day.
Using the incidents DataFrame, return one row per service. Keep service as a column, then one column per day, named 2024-10-01, 2024-10-02, 2024-10-03 and 2024-10-04, holding the hours lost on that day rounded to 2 decimal places. A service with nothing on a day shows 0. 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 |
| 6006 | search-api | 2024-10-01 01:00:00 | 2024-10-01 01:35:00 | SEV3 |
| 6007 | search-api | 2024-10-01 05:20:00 | 2024-10-01 08:05:00 | SEV1 |
| 6008 | search-api | 2024-10-01 07:15:00 | 2024-10-01 07:50:00 | SEV3 |
| 6009 | search-api | 2024-10-02 14:00:00 | 2024-10-02 14:20:00 | SEV3 |
| 6010 | search-api | 2024-10-03 11:45:00 | 2024-10-03 13:10:00 | SEV2 |
| 6020 | checkout-api | 2024-10-04 07:00:00 | 2024-10-04 07:25:00 | SEV3 |
Example Output
| service | 2024-10-01 | 2024-10-02 | 2024-10-03 | 2024-10-04 |
|---|---|---|---|---|
| checkout-api | 3.58 | 2.42 | 0 | 0.42 |
| search-api | 3.92 | 0.33 | 1.42 | 0 |
Explanation
The checkout service lost 3.58 hours on the first day and 2.42 on the second, then nothing on the third, which shows as 0 rather than an empty cell. The search service lost time on three of the four days.
The example above is a small slice of the data. Your code runs against the full DataFrames.
Company
PagerDuty
Difficulty
hard
Topic
reshaping
Language
Pandas
Your code
Loading Python in the background. You can start writing.