Skip to content
Advertisement

Creating time delta diff column based on groupby id

I have the following sample df

JavaScript

I want to groupby Id, and get the timedelta difference between the timestamps, i manage to get something similar to the wanted series. Through this code. Although, it is taking quite a long time, is there a way to do it more efficiently?

JavaScript

Wanted series

JavaScript

Advertisement

Answer

here is one way about it btw, if you groupby ID, then the desired result you shared is incorrected. the third row should be zero since its a different ID

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