Skip to content

Fill null values using interpolation based on another column

Description

Fill null values using interpolation based on another column

Usage

<Expr>$interpolate_by(by)

Arguments

by Column to interpolate values based on.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(a = c(1, NA, NA, 3), b = c(1, 2, 7, 8))
df$with_columns(
  a_interpolated = pl$col("a")$interpolate_by("b")
)
#> shape: (4, 3)
#> ┌──────┬─────┬────────────────┐
#> │ a    ┆ b   ┆ a_interpolated │
#> │ ---  ┆ --- ┆ ---            │
#> │ f64  ┆ f64 ┆ f64            │
#> ╞══════╪═════╪════════════════╡
#> │ 1.0  ┆ 1.0 ┆ 1.0            │
#> │ null ┆ 2.0 ┆ 1.285714       │
#> │ null ┆ 7.0 ┆ 2.714286       │
#> │ 3.0  ┆ 8.0 ┆ 3.0            │
#> └──────┴─────┴────────────────┘