total_seconds()
noun
say it: “TOH-tul SEK-undz” /ˈtoʊtəl ˈsɛkəndz/
A pandas method that turns a length of time, such as 27 minutes 15 seconds, into one number of seconds, here 1635.
What does total_seconds() do in pandas?
total_seconds() gives a length of time (a Timedelta) as one number of seconds; on a column it's
.dt.total_seconds(). Dividing by 60 then gives minutes, which can be averaged or divided by a distance to get a pace.
import pandas as pd
times = pd.to_timedelta(pd.Series(["0:27:15", "0:31:40"]))
print(times.dt.total_seconds() / 60) # 27.25, 31.666...
In a sentence
- “She divided total_seconds() by 60 to get each runner's minutes.”
- “total_seconds() turned 0:27:15 into 1635 seconds.”
Level: Journeyman · More Python terms at this level
Updated