12

Dates and Times

One of the bigger reasons for using Pandas is its ability to work with timeseries data. We observed some of this capability earlier, when we concatenated data in Chapter 6 and saw how the indices automatically aligned themselves. This chapter focuses on the more common tasks encountered when working with data that involve dates and times.

Learning Objectives

  • Create date objects with the datetime library

  • Use functions to convert strings into a date

  • Use functions to format dates

  • Perform date calculations

  • Use functions to resample dates

  • Use functions to work with and convert time zones

12.1 Python's datetime Object

Python has a built-in datetime object that is found in the datetime library.

Get Pandas for Everyone: Python Data Analysis, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.