My Pandas dataframe has a sorted column of datetimes:
print(df.Time)
returns
0 2019-10-30 13:14:49
1 2019-10-30 13:15:25
2 2019-10-30 13:32:44
...
997 2020-02-04 13:53:35
998 2020-02-04 14:22:46
999 2020-02-04 14:52:43
Name: Time, Length: 1000, dtype: datetime64[ns]
The very simple thing I'm attempting is to derive an array of timedeltas. I've tried:
df.Time[1:-1] - df.Time[0:-2]
which results in:
0 NaT
1 0 days
2 0 days
...
996 0 days
997 0 days
998 NaT
Name: Time, Length: 999, dtype: timedelta64[ns]
The resulting length is correct, but I'm a little confused by the result.
It seems this is not the way to perform an operation on 2 subsets of a dataframe.
What is the correct approach, and is there a builtin method that produces timedeltas from a sorted column of datetimes?
Intended output looks something like:
0 35 seconds
1 1879 seconds
2 1720 seconds
...
996 1805 seconds
997 1854 seconds
998 1791 seconds