Book Image

Learning Pandas

By : Michael Heydt
Book Image

Learning Pandas

By: Michael Heydt

Overview of this book

Table of Contents (19 chapters)
Learning pandas
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Calculating new dates using offsets


Frequencies in pandas are represented using date offsets. We have touched on this concept at the beginning of the chapter when discussing Timedelta objects. pandas extends the capabilities of these using the concept of DateOffset objects, which represent knowledge of how to integrate time offsets and frequencies relative to DatetimeIndex objects.

We will examine how pandas uses date offsetting in two different ways. The first calculates offsets of a specific duration from a given date, and the other calculates offsets based on what are referred to as anchored offsets.

Date offsets

DatetimeIndex objects are created at various frequencies by passing in frequency strings, such as 'M', 'W', and 'BM' to the freq parameter of pd.date_range(). Under the hood, these frequency strings are translated into an instance of the pandas DateOffset object, which is associated with the frequency of the index.

DateOffset represents a regular frequency increment. Specific date...