upby.SeriesGroupBy.rolling ](pandas.core.groupby.SeriesGroupBy.rolling.html)
    * [ pandas.core.groupby.SeriesGroupBy.sample ](pandas.core.groupby.SeriesGroupBy.sample.html)
    * [ pandas.core.groupby.SeriesGroupBy.sem ](pandas.core.groupby.SeriesGroupBy.sem.html)
    * [ pandas.core.groupby.SeriesGroupBy.shift ](pandas.core.groupby.SeriesGroupBy.shift.html)
    * [ pandas.core.groupby.SeriesGroupBy.size ](pandas.core.groupby.SeriesGroupBy.size.html)
    * [ pandas.core.groupby.SeriesGroupBy.skew ](pandas.core.groupby.SeriesGroupBy.skew.html)
    * [ pandas.core.groupby.SeriesGroupBy.std ](pandas.core.groupby.SeriesGroupBy.std.html)
    * [ pandas.core.groupby.SeriesGroupBy.sum ](pandas.core.groupby.SeriesGroupBy.sum.html)
    * [ pandas.core.groupby.SeriesGroupBy.var ](pandas.core.groupby.SeriesGroupBy.var.html)
    * [ pandas.core.groupby.SeriesGroupBy.tail ](pandas.core.groupby.SeriesGroupBy.tail.html)
    * [ pandas.core.groupby.SeriesGroupBy.take ](pandas.core.groupby.SeriesGroupBy.take.html)
    * [ pandas.core.groupby.SeriesGroupBy.value_counts ](pandas.core.groupby.SeriesGroupBy.value_counts.html)
    * [ pandas.core.groupby.DataFrameGroupBy.boxplot ](pandas.core.groupby.DataFrameGroupBy.boxplot.html)
    * [ pandas.core.groupby.DataFrameGroupBy.hist ](pandas.core.groupby.DataFrameGroupBy.hist.html)
    * [ pandas.core.groupby.SeriesGroupBy.hist ](pandas.core.groupby.SeriesGroupBy.hist.html)
    * [ pandas.core.groupby.DataFrameGroupBy.plot ](pandas.core.groupby.DataFrameGroupBy.plot.html)
    * [ pandas.core.groupby.SeriesGroupBy.plot ](pandas.core.groupby.SeriesGroupBy.plot.html)
  * [ Resampling ](../resampling.html)
  * [ Style ](../style.html)
  * [ Plotting ](../plotting.html)
  * [ Options and settings ](../options.html)
  * [ Extensions ](../extensions.html)
  * [ Testing ](../testing.html)
  * [ Missing values ](../missing_value.html)

  * [ __ ](../../index.html)
  * [ API reference ](../index.html)
  * [ GroupBy ](../groupby.html)
  * pandas.core.... 

#  pandas.core.groupby.DataFrameGroupBy.shift  #

DataFrameGroupBy.  shift  (  _ periods  =  1  _ , _ freq  =  None  _ , _ axis
=  _NoDefault.no_default  _ , _ fill_value  =  _NoDefault.no_default  _ , _
suffix  =  None  _ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/groupby/groupby.py#L5088-L5243) #

    

Shift each group by periods observations.

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

Parameters  :

    

**periods** int | Sequence[int], default 1 
    

Number of periods to shift. If a list of values, shift each group by each
period.

**freq** str, optional

    

Frequency string.

**axis** axis to shift, default 0

    

Shift direction.

Deprecated since version 2.1.0:  For axis=1, operate on the underlying object
instead. Otherwise the axis keyword is not necessary.

**fill_value** optional

    

The scalar value to use for newly introduced missing values.

Changed in version 2.1.0:  Will raise a ` ValueError  ` if ` freq  ` is
provided too.

**suffix** str, optional

    

A string to add to each shifted column if there are multiple periods. Ignored
otherwise.

Returns  :

    

Series or DataFrame

    

Object shifted within each group.

See also

` Index.shift  `

    

Shift values of Index.

Examples

For SeriesGroupBy:

    
    
    >>> lst = ['a', 'a', 'b', 'b']
    >>> ser = pd.Series([1, 2, 3, 4], index=lst)
    >>> ser
    a    1
    a    2
    b    3
    b    4
    dtype: int64
    >>> ser.groupby(level=0).shift(1)
    a    NaN
    a    1.0
    b    NaN
    b    3.0
    dtype: float64
    

For DataFrameGroupBy:

    
    
    >>> data = [[1, 2, 3], [1, 5, 6], [2, 5, 8], [2, 6, 9]]
    >>> df = pd.DataFrame(data, columns=["a", "b", "c"],
    ...                   index=["tuna", "salmon", "catfish", "goldfish"])
    >>> df
               a  b  c
        tuna   1  2  3
      salmon   1  5  6
     catfish   2  5  8
    goldfish   2  6  9
    >>> df.groupby("a").shif