maxframe.liteframe.LiteFrame.diff#

LiteFrame.diff(periods=1, columns=None)#

Compute x[i] - x[i-periods] for each row.

First periods rows (for positive periods) or last |periods| rows (for negative periods) are null.

Parameters:
  • periods (int, default 1) – Number of positions to diff. Positive = forward, negative = backward.

  • columns (str, list of str, or None, default None) – Column(s) to diff. If None, all columns are diffed. Non-selected columns are passed through unchanged.

Returns:

Diffed LiteFrame with same shape and columns.

Return type:

LiteFrame

Raises:

TypeError – If any transformed column is non-numeric.

See also

shift

Shift rows by a given number of periods.

pct_change

Compute percent change over given periods.

Examples

>>> import maxframe.liteframe as mlf
>>> lf = mlf.LiteFrame({'a': [1, 2, 4, 7]})
>>> result = lf.diff()
>>> result.execute()
     a
0  NaN
1  1.0
2  2.0
3  3.0