pandas.core.groupby.DataFrameGroupBy.shift#

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

Shift each group by periods observations.

If freq is passed, the index will be increased using the periods and the freq.

Parameters
periodsint, default 1

Number of periods to shift.

freqstr, optional

Frequency string.

axisaxis to shift, default 0

Shift direction.

fill_valueoptional

The scalar value to use for newly introduced missing values.

Returns
Series or DataFrame

Object shifted within each group.

See also

Index.shift

Shift values of Index.