Skip to content

Fill null values forward

Source code

Description

Fill missing values with the last seen values. Syntactic sugar for $fill_null(strategy = “forward”).

Usage

<Expr>$forward_fill(limit = NULL)

Arguments

limit Number of consecutive null values to fill when using the “forward” or “backward” strategy.

Value

Expr

Examples

library(polars)

pl$DataFrame(a = c(NA, 1, NA, 2, NA))$
  with_columns(
  backward = pl$col("a")$forward_fill()
)
#> shape: (5, 2)
#> ┌──────┬──────────┐
#> │ a    ┆ backward │
#> │ ---  ┆ ---      │
#> │ f64  ┆ f64      │
#> ╞══════╪══════════╡
#> │ null ┆ null     │
#> │ 1.0  ┆ 1.0      │
#> │ null ┆ 1.0      │
#> │ 2.0  ┆ 2.0      │
#> │ null ┆ 2.0      │
#> └──────┴──────────┘