pandas.Index.shift

pandas 3.1.1 · Index objects · method

Move time-based index labels by the requested number of frequency steps.

Call syntax

Index.shift(periods=1, freq=None)

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
periods Optional
Positional or keyword
Default 1
int

Set a count of generated observations or the number of steps to shift or compare.

freq Optional
Positional or keyword
Default None
pandas.DateOffset, pandas.Timedelta or str

Specify the frequency or offset, such as "D" for a day or "MS" for a calendar month start.

Returns

pandas.Index