DataFrameGroupBy.shift(periods=1, freq=None, axis=0, fill_value=None)[source]#

Shift each group by periods positions.

periodsint, default 1

Number of periods to shift.

freqstr, unsupported
axis0, axis to shift

Shift direction. Only row-wise shift is supported

fill_valuescalar or list of scalars, optional

The scalar value to use for newly introduced missing values. Can be specified with None, a single value or multiple values:

  • None (default): sets all indeterminable values to null.

  • Single value: fill all shifted columns with this value. Should match the data type of all columns.

  • List of values: fill shifted columns with corresponding value in the list. The length of the list should match the number of columns shifted. Each value should match the data type of the column to fill.

Series or DataFrame

Object shifted within each group.

Pandas Compatibility Note


Parameter freq is unsupported.