Fill null values using the specified value or strategy
Description
Fill null values using the specified value or strategy
Usage
<DataFrame>$fill_null(
value,
strategy = NULL,
limit = NULL,
...,
matches_supertype = TRUE
)
Arguments
value
|
Value used to fill null values. |
strategy
|
Strategy used to fill null values. Must be one of:
“forward” , “backward” , “min” ,
“max” , “mean” , “zero” ,
“one” , or NULL (default).
|
limit
|
Number of consecutive null values to fill when using the
“forward” or “backward” strategy.
|
…
|
These dots are for future extensions and must be empty. |
matches_supertype
|
Fill all matching supertypes of the fill value literal.
|
Value
A polars DataFrame
Examples
library("polars")
df <- pl$DataFrame(
a = c(1.5, 2, NA, 4),
b = c(1.5, NA, NA, 4)
)
df$fill_null(99)
#> shape: (4, 2)
#> ┌──────┬──────┐
#> │ a ┆ b │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞══════╪══════╡
#> │ 1.5 ┆ 1.5 │
#> │ 2.0 ┆ 99.0 │
#> │ 99.0 ┆ 99.0 │
#> │ 4.0 ┆ 4.0 │
#> └──────┴──────┘
#> shape: (4, 2)
#> ┌─────┬─────┐
#> │ a ┆ b │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞═════╪═════╡
#> │ 1.5 ┆ 1.5 │
#> │ 2.0 ┆ 1.5 │
#> │ 2.0 ┆ 1.5 │
#> │ 4.0 ┆ 4.0 │
#> └─────┴─────┘
#> shape: (4, 2)
#> ┌─────┬─────┐
#> │ a ┆ b │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞═════╪═════╡
#> │ 1.5 ┆ 1.5 │
#> │ 2.0 ┆ 4.0 │
#> │ 4.0 ┆ 4.0 │
#> │ 4.0 ┆ 4.0 │
#> └─────┴─────┘
#> shape: (4, 2)
#> ┌─────┬─────┐
#> │ a ┆ b │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞═════╪═════╡
#> │ 1.5 ┆ 1.5 │
#> │ 2.0 ┆ 0.0 │
#> │ 0.0 ┆ 0.0 │
#> │ 4.0 ┆ 4.0 │
#> └─────┴─────┘