mars.dataframe.Series.diff#
- Series.diff(periods=1)#
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).
- 参数
periods (int, default 1) – Periods to shift for calculating difference, accepts negative values.
- 返回
First differences of the Series.
- 返回类型
参见
Series.pct_changePercent change over given number of periods.
Series.shiftShift index by desired number of periods with an optional time freq.
DataFrame.diffFirst discrete difference of object.
备注
For boolean dtypes, this uses
operator.xor()rather thanoperator.sub().示例
Difference with previous row
>>> import mars.dataframe as md >>> s = md.Series([1, 1, 2, 3, 5, 8]) >>> s.diff().execute() 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).execute() 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).execute() 0 0.0 1 -1.0 2 -1.0 3 -2.0 4 -3.0 5 NaN dtype: float64