pandas.DataFrame.shift

pandas 3.1.1 · DataFrame · method

Move values by a positional offset. With a time frequency, move the labels instead.

Call syntax

DataFrame.shift(periods=1, freq=None, axis=0, fill_value=…, suffix=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 or Sequence

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

freq Optional
Positional or keyword
Default None
DateOffset, tseries.offsets, timedelta, or str

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

axis Optional
Positional or keyword
Default 0
{0 or 'index', 1 or 'columns', None}

Choose which axis the operation acts on. The accepted axis labels depend on the receiver.

fill_value Optional
Positional or keyword
object

Supply a value to use in place of a missing position.

suffix Optional
Positional or keyword
Default None
str

Set the text added to labels or the pattern used for wide-column suffixes.

Returns

DataFrame