Skip to content
Advertisement

How to calculate difference in DATE based on status of another column?

I have the following dataset,

JavaScript

I want to create a new field name “duration” which will capture the time difference between SWO issued and rescinded for each BIN number. Note that, each BIN number can show up multiple times based on Date and different Unit. So, each unit can issue SWO on the same BIN number.

I am trying to get a output like this which will calculate the date difference in days on the BIN number by Unit and based on SWO Issued and Rescinded.

Output:

JavaScript

I used this but it groupby on Unit rather than giving me individual BIN Number by each unit and their dispositions status,

JavaScript

Appreciate any help

Advertisement

Answer

IIUC,

you need to groupby and use diff to calculate the delta in time values,

you can then merge onto your original df.

JavaScript

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