Drop all rows that contain null values
Description
The original order of the remaining rows is preserved.
Usage
<LazyFrame>$drop_nulls(...)
Arguments
…
|
\<dynamic-dots \> Column name(s) for which null values are
considered. If empty (default), use all columns.
|
Value
A polars LazyFrame
Examples
library("polars")
lf <- pl$LazyFrame(
foo = 1:3,
bar = c(6L, NA, 8L),
ham = c("a", "b", NA)
)
# The default behavior of this method is to drop rows where any single value
# of the row is null.
lf$drop_nulls()$collect()
#> shape: (1, 3)
#> ┌─────┬─────┬─────┐
#> │ foo ┆ bar ┆ ham │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ i32 ┆ str │
#> ╞═════╪═════╪═════╡
#> │ 1 ┆ 6 ┆ a │
#> └─────┴─────┴─────┘
# This behaviour can be constrained to consider only a subset of columns, as
# defined by name or with a selector. For example, dropping rows if there is
# a null in any of the integer columns:
lf$drop_nulls(cs$integer())$collect()
#> shape: (2, 3)
#> ┌─────┬─────┬──────┐
#> │ foo ┆ bar ┆ ham │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ i32 ┆ str │
#> ╞═════╪═════╪══════╡
#> │ 1 ┆ 6 ┆ a │
#> │ 3 ┆ 8 ┆ null │
#> └─────┴─────┴──────┘