Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get minute difference for every 2 datetime objects

I have a pandas DF

time                     #
2021-11-04 04:34:55 PM   1
2021-11-04 04:36:55 PM   2
2021-11-04 04:39:55 PM   3
2021-11-04 04:45:55 PM   4
2021-11-04 04:46:55 PM   5
2021-11-04 04:47:55 PM   6
2021-11-04 04:49:55 PM   7
2021-11-04 04:53:55 PM   8
2021-11-04 04:57:55 PM   9
...

I want to calculate the time difference between each number and store that in a column for each value. So the column will have output
02:00, 03:00,....

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Perhaps simply:

df['time'].diff()

Or, if time is the index():

pd.Series(df.index).diff()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading