w3resource

Pandas Series: dt.total_seconds() function

Series-dt.total_seconds() function

The dt.total_seconds() function is used to return total duration of each element expressed in seconds.

This method is available directly on TimedeltaArray, TimedeltaIndex and on Series containing timedelta values under the .dt namespace.

Series.dt.total_seconds(self, *args, **kwargs)
Pandas Series: dt.total_seconds() function

Returns: seconds - [ndarray, Float64Index, Series]
When the calling object is a TimedeltaArray, the return type is ndarray. When the calling object is a TimedeltaIndex, the return type is a Float64Index. When the calling object is a Series, the return type is Series of type float64 whose index is the same as the original.

Example - Series:

Python-Pandas Code:

import numpy as np
import pandas as pd

Example - TimedeltaIndex:

Python-Pandas Code:

import numpy as np
import pandas as pd
idx = pd.to_timedelta(np.arange(6), unit='d')
idx

Output:

TimedeltaIndex(['0 days', '1 days', '2 days', '3 days', '4 days', '5 days'], dtype='timedelta64[ns]', freq=None)

Python-Pandas Code:

import numpy as np
import pandas as pd
idx = pd.to_timedelta(np.arange(6), unit='d')
idx.total_seconds()

Output:

Float64Index([0.0, 86400.0, 172800.0, 259200.00000000003, 345600.0, 432000.0], dtype='float64')

Previous: Series-dt.to_pytimedelta() function
Next: Series-str.capitalize() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/pandas/series/series-dt-total_seconds.php