to_timedelta()
noun
say it: “too TYM-del-tuh” /tu ˈtaɪmˌdɛltə/
A pandas function that turns text such as "0:27:15", written as hours, minutes and seconds, into a length of time.
What does to_timedelta() do in pandas?
to_timedelta() (pd.to_timedelta) turns text written as hours:minutes:seconds, such as "0:27:15", into a
Timedelta, a length of time that sorts and averages correctly. It stops on text it can't read, such as "27:15"
with the hours left off, unless you add errors="coerce".
import pandas as pd
times = pd.to_timedelta(pd.Series(["0:27:15", "0:31:40"]))
print(times.mean()) # 0 days 00:29:27.500000
In a sentence
- “"27:15" made to_timedelta() stop, because the hours were missing.”
- “to_timedelta() turned the typed finish times into durations.”
Level: Journeyman · More Python terms at this level
Updated