maxframe.liteframe.LiteFrame.pct_change#

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

Compute (x[i] - x[i-periods]) / x[i-periods] for each row.

First periods rows (for positive periods) or last |periods| rows (for negative periods) are null. Division by zero produces null/inf following Polars arithmetic semantics.

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

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

Returns:

Pct-change LiteFrame with same shape. Transformed columns become Float64.

Return type:

LiteFrame

Raises:

TypeError – If any transformed column is non-numeric.

See also

diff

Compute the difference between consecutive rows.

shift

Shift rows by a given number of periods.

Examples

>>> import maxframe.liteframe as mlf
>>> lf = mlf.LiteFrame({'a': [100, 110, 121]})
>>> result = lf.pct_change()
>>> result.execute()
     a
0  NaN
1  0.1
2  0.1