Home > Blockchain >  How to get minute difference for every 2 datetime objects
How to get minute difference for every 2 datetime objects

Time:04-20

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,....

CodePudding user response:

Perhaps simply:

df['time'].diff()

Or, if time is the index():

pd.Series(df.index).diff()
  • Related