1# Convert TimeDelta column (5 days etc.) into an integer column (5)
2import numpy as np
3df.timeDelta = (df.timeDelta / np.timedelta64(1,'D')).astype(int)
1# convert the entire timedelta to seconds
2# this is the same as td / timedelta(seconds=1)
3(df.from_date - df.to_date).dt.total_seconds()
4[out]:
50 211089.82
61 13264.30
72 31373.76
8dtype: float64
9
10# get the number of days
11(df.from_date - df.to_date).dt.days
12[out]:
130 2
141 0
152 0
16dtype: int64
17
18# get the seconds for hours + minutes + seconds, but not days
19# note the difference from total_seconds
20(df.from_date - df.to_date).dt.seconds
21[out]:
220 38289
231 13264
242 31373
25dtype: int64
26