The dt Accessor

Learn how to use the dt accessor of Pandas to perform vectorized operations.

How to work with dates in a DataFrame

In the previous lesson, we covered different ways to extract a piece of information from a Timestamp object. However, we only worked with a single object. In most cases, we don’t work with single values but with data stored in a DataFrame. A typical DataFrame of transactional sales at a retail store might contain millions of rows.

For instance, an operation that extracts the month from a date is performed on an entire column. The Pandas library also provides methods to perform such tasks, which are accessed via the dt accessor. The dt accessor is similar to the str accessor. It serves as a gate to Pandas functions and methods for date and time manipulation on a DataFrame. Let’s run through an example on the staff:

Get hands-on with 1200+ tech skills courses.