Skip to content

Apply logical AND on two expressions

Source code

Description

Combine two boolean expressions with AND.

Usage

<Expr>$and(...)

Arguments

\<dynamic-dots\> One or more integer or boolean expressions to evaluate/combine.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  x = c(5, 6, 7, 4, 8),
  y = c(1.5, 2.5, 1.0, 4.0, -5.75),
  z = c(-9, 2, -1, 4, 8),
)
df$with_columns(
  (pl$col("x") >= pl$col("z"))$and(
    pl$col("y") >= pl$col("z"),
    pl$col("y") == pl$col("y"),
    pl$col("z") <= pl$col("x"),
    pl$col("y") != pl$col("x"),
  )$alias("all")
)
#> shape: (5, 4)
#> ┌─────┬───────┬──────┬───────┐
#> │ x   ┆ y     ┆ z    ┆ all   │
#> │ --- ┆ ---   ┆ ---  ┆ ---   │
#> │ f64 ┆ f64   ┆ f64  ┆ bool  │
#> ╞═════╪═══════╪══════╪═══════╡
#> │ 5.0 ┆ 1.5   ┆ -9.0 ┆ true  │
#> │ 6.0 ┆ 2.5   ┆ 2.0  ┆ true  │
#> │ 7.0 ┆ 1.0   ┆ -1.0 ┆ true  │
#> │ 4.0 ┆ 4.0   ┆ 4.0  ┆ false │
#> │ 8.0 ┆ -5.75 ┆ 8.0  ┆ false │
#> └─────┴───────┴──────┴───────┘