Answers for "pd.timedelta"

0

converting pandas._libs.tslibs.timedeltas.Timedelta to days

# Convert TimeDelta column (5 days etc.) into an integer column (5)
import numpy as np
df.timeDelta = (df.timeDelta / np.timedelta64(1,'D')).astype(int)
Posted by: Guest on December-03-2020
0

pd.timedelta

# convert the entire timedelta to seconds
# this is the same as td / timedelta(seconds=1)
(df.from_date - df.to_date).dt.total_seconds()
[out]:
0    211089.82
1     13264.30
2     31373.76
dtype: float64

# get the number of days
(df.from_date - df.to_date).dt.days
[out]:
0    2
1    0
2    0
dtype: int64

# get the seconds for hours + minutes + seconds, but not days
# note the difference from total_seconds
(df.from_date - df.to_date).dt.seconds
[out]:
0    38289
1    13264
2    31373
dtype: int64
Posted by: Guest on September-24-2021

Code answers related to "pd.timedelta"

Python Answers by Framework

Browse Popular Code Answers by Language