.groupby.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.SeriesGroupBy.diff  #

SeriesGroupBy.  diff  (  _ periods  =  1  _ , _ axis  =  _NoDefault.no_default
_ )  [ [source]  ](https://github.com/pandas-
dev/pandas/blob/v2.2.2/pandas/core/groupby/groupby.py#L5245-L5343) #

    

First discrete difference of element.

Calculates the difference of each element compared with another element in the
group (default is element in previous row).

Parameters  :

    

**periods** int, default 1

    

Periods to shift for calculating difference, accepts negative values.

**axis** axis to shift, default 0

    

Take difference over rows (0) or columns (1).

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

Returns  :

    

Series or DataFrame

    

First differences.

See also

` Series.groupby  `

    

Apply a function groupby to a Series.

` DataFrame.groupby  `

    

Apply a function groupby to each row or column of a DataFrame.

Examples

For SeriesGroupBy:

    
    
    >>> lst = ['a', 'a', 'a', 'b', 'b', 'b']
    >>> ser = pd.Series([7, 2, 8, 4, 3, 3], index=lst)
    >>> ser
    a     7
    a     2
    a     8
    b     4
    b     3
    b     3
    dtype: int64
    >>> ser.groupby(level=0).diff()
    a    NaN
    a   -5.0
    a    6.0
    b    NaN
    b   -1.0
    b    0.0
    dtype: float64
    

For DataFrameGroupBy:

    
    
    >>> data = {'a': [1, 3, 5, 7, 7, 8, 3], 'b': [1, 4, 8, 4, 4, 2, 1]}
    >>> df = pd.DataFrame(data, index=['dog', 'dog', 'dog',
    ...                   'mouse', 'mouse', 'mouse', 'mouse'])
    >>> df
             a  b
      dog    1  1
      dog    3  4
      dog    5  8
    mouse    7  4
    mouse    7  4
    mouse    8  2
    mouse    3  1
    >>> df.groupby(level=0).diff()
             a    b
      dog  NaN  NaN
      dog  2.0  3.0
      dog  2.0  4.0
    mouse  NaN  NaN
    mouse  0.0  0.0
    mouse  1.0 -2.0
    mouse -5.0 -1.0
    

[ __ previous  pandas.core.group