Closer Look at Time Deltas

Discover the attributes and methods of the Timedelta object for time series.

Introduction

Having earlier focused more on the popular concepts of Timestamp and DatetimeIndex, it’ll be good for us to take a closer look at another time series topic—time deltas.

As a refresher, a time delta represents the difference between two dates or times. It’s a duration that can be positive, negative, or zero. Time deltas are useful in various applications, such as calculating the time elapsed between events, determining deadlines, or analyzing time-based patterns in data.

Time deltas are represented using the Timedelta class, which provides various methods and attributes to work with time deltas efficiently.

Creating time deltas

There are several ways to create time deltas in pandas. Let’s explore some of the most common methods, starting with the Timedelta class and corresponding unit keyword parameters.

The example below shows how we can generate time delta objects by specifying plural keyword parameters like days, hours, and minutes:

Get hands-on with 1200+ tech skills courses.