concept Timedelta in category pandas

appears as: Timedelta
Pandas in Action

This is an excerpt from Manning's book Pandas in Action.

In this chapter, we'll review Python's built-in solutions for datetimes and how Pandas improves upon them with the Timestamp and Timedelta objects. We'll see how we can use the library to convert strings to dates, add and subtract offsets of time, calculate durations, and more. Let's dive in.

The Timedelta constructor is available at the top level of the pandas library. Much like the datetime module's timedelta constructor, it accepts keyword parameters for units of time like days, hours, minutes, and seconds. It's easy to confuse the two objects; timedelta is built into Python, Timedelta is built into pandas. The two are mostly interchangeable when used with pandas operations.

In  [73] duration = pd.Timedelta(days = 8, hours = 7,
                                 minutes = 6, seconds = 5)
         duration
 
Out [73] Timedelta('8 days 07:06:05')

The to_timedelta function at the top-level of the pandas library converts its argument to a Timedelta object. It is to Timedeltas what to_datetimes is to datetimes. Below, we convert a string to a Timedelta object.