Skip to content
Advertisement

Calculate time between two different values in the same pandas column

I have data that look like the following

JavaScript

I need to create a new column that will find the time between the first issue and the first resolved. I need a groupby statement that will keep the first issue and the first resolved for all the issues. Then find the time – When I use group by Device and condition it just kept one issue per device.

The desired output is like the following

JavaScript

As groupby Device and Condition is not enough I thought to create an index column

JavaScript

Then use pivot table for the time calculations

JavaScript

Advertisement

Answer

The biggest problem is how to group your issues/resolved properly, which can be done by a reversed cumsum:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement