Pandas Series.dt.total_seconds() not found

total_seconds is a member of timedelta not datetime

Hence the error

You maybe be wanting dt.second

This returns the second component which is different to total_seconds

So you need to perform some kind of arithmetic operation such as deleting something against this in order to generate a series of timedeltas, then you can do dt.total_seconds

Example:

In[278]:
s = s - pd.datetime.now()
s

Out[278]: 
0   -1 days +23:59:46.389639
1   -1 days +23:59:46.389639
2   -1 days +23:59:46.389639
3   -1 days +23:59:46.389639
4   -1 days +23:59:46.389639
5   -1 days +23:59:46.389639
6   -1 days +23:59:46.389639
7   -1 days +23:59:46.389639
8   -1 days +23:59:46.389639
9   -1 days +23:59:46.389639
dtype: timedelta64[ns]

In[279]:
s.dt.total_seconds()

Out[279]: 
0   -13.610361
1   -13.610361
2   -13.610361
3   -13.610361
4   -13.610361
5   -13.610361
6   -13.610361
7   -13.610361
8   -13.610361
9   -13.610361
dtype: float64

Actually I just realized you could just convert to integer (in case you want the total seconds)!

>>> df.time_column.astype(int)
0     1592294727721713000
1     1592294727650772000
2     1592294727682569000
3     1592294727712650000

Tags:

Python

Pandas