O'Reilly logo

Learning pandas - Second Edition by Michael Heydt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Shifting and lagging

A common operation on time-series data is to shift the values backward and forward in time. The pandas method for this is .shift() which will shift values in a Series or DataFrame a specified number of units of the frequency in the index.

To demonstrate shifting, we will use the following Series. This Series has five values, is indexed by date starting at 2014-08-01, and uses a daily frequency:

The following shifts the values forward by 1 day:

pandas has moved the values forward one unit of the index's frequency, which ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required