Skip to content
Advertisement

Arranging call data from salesforce in 15 minute intervals

I am new in python and pandas and also in stackoverflow so I apologize for any mistakes I make in advance.

I have this dataframe

JavaScript

output is

JavaScript

and my desired outcome is to have something like in below

JavaScript

I have this code from another topic link

JavaScript

But it does not take “interval_start” into consideration, I need to check first if the status_duration will remain on same 15 mins interval or not. Hope somebody can help as it is a very advanced problem for me and i am working on it for more than 10 days.

Advertisement

Answer

After learning a bit more, I came up with another (better) solution using groupby() and explode(). I add this as a second answer since my first one, while maybe a bit complicated, still works and I am also referencing a part of it in this answer.


I first added a few new columns to split up the status_duration into the first slice and the rest and replaced the original value of status_duration with an according 2-element list:

JavaScript

This gives you the following prepared dataframe:

JavaScript

On this, you can now perform a groupby() and explode() similar to the code in your question. Afterwards you round the intervals and group again to merge the intervals that have multiple entries now because of the explode(). To clean up, I dropped the rows with duration 0 and reset the index:

JavaScript

This gives you your desired output:

JavaScript

Note: The problem I described in the other answer, that the final grouping step could result in a status_duration > 900 should not be possible with real data, since a specialist shouldn’t be able to start a second interval before the first one ends. So this is a case you do not need to handle after all.

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