Series.diff(self, periods=1)
[source]
First discrete difference of element.
Calculates the difference of a Series element compared with another element in the Series (default is element in previous row).
Parameters: |
|
---|---|
Returns: |
|
See also
Series.pct_change
Series.shift
DataFrame.diff
Difference with previous row
>>> s = pd.Series([1, 1, 2, 3, 5, 8]) >>> s.diff() 0 NaN 1 0.0 2 1.0 3 1.0 4 2.0 5 3.0 dtype: float64
Difference with 3rd previous row
>>> s.diff(periods=3) 0 NaN 1 NaN 2 NaN 3 2.0 4 4.0 5 6.0 dtype: float64
Difference with following row
>>> s.diff(periods=-1) 0 0.0 1 -1.0 2 -1.0 3 -2.0 4 -3.0 5 NaN dtype: float64
© 2008–2012, AQR Capital Management, LLC, Lambda Foundry, Inc. and PyData Development Team
Licensed under the 3-clause BSD License.
https://pandas.pydata.org/pandas-docs/version/0.25.0/reference/api/pandas.Series.diff.html