Answers for "pandas Timedelta to datetime.timedelta"

1

pandas timedelta to seconds

df['column_with_timedelta'].dt.total_seconds()
Posted by: Guest on August-25-2021
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 "pandas Timedelta to datetime.timedelta"

Python Answers by Framework

Browse Popular Code Answers by Language