Method: Polars::Expr#diff

Defined in:
lib/polars/expr.rb

#diff(n: 1, null_behavior: "ignore") ⇒ Expr

Calculate the n-th discrete difference.

Examples:

df = Polars::DataFrame.new(
  {
    "a" => [20, 10, 30]
  }
)
df.select(Polars.col("a").diff)
# =>
# shape: (3, 1)
# ┌──────┐
# │ a    │
# │ ---  │
# │ i64  │
# ╞══════╡
# │ null │
# │ -10  │
# │ 20   │
# └──────┘

Parameters:

  • n (Integer) (defaults to: 1)

    Number of slots to shift.

  • null_behavior ("ignore", "drop") (defaults to: "ignore")

    How to handle null values.

Returns:


5891
5892
5893
# File 'lib/polars/expr.rb', line 5891

def diff(n: 1, null_behavior: "ignore")
  _from_rbexpr(_rbexpr.diff(n, null_behavior))
end