polars.Expr.or_#
- Expr.or_(*others: Any) Expr[source]#
Method equivalent of bitwise “or” operator
expr | other | ....This has the effect of combining logical boolean expressions, but operates bitwise on integers.
- Parameters:
- *others
One or more integer or boolean expressions to evaluate/combine.
Examples
>>> df = pl.DataFrame( ... data={ ... "x": [5, 6, 7, 4, 8], ... "y": [1.5, 2.5, 1.0, 4.0, -5.75], ... "z": [-9, 2, -1, 4, 8], ... } ... )
Combine logical “or” conditions:
>>> df.select( ... (pl.col("x") == pl.col("y")) ... .or_( ... pl.col("x") == pl.col("y"), ... pl.col("y") == pl.col("z"), ... pl.col("y").cast(int) == pl.col("z"), ... ) ... .alias("any") ... ) shape: (5, 1) ┌───────┐ │ any │ │ --- │ │ bool │ ╞═══════╡ │ false │ │ true │ │ false │ │ true │ │ false │ └───────┘
Bitwise “or” operation on integer columns:
>>> df.select("x", "z", x_or_z=pl.col("x").or_(pl.col("z"))) shape: (5, 3) ┌─────┬─────┬────────┐ │ x ┆ z ┆ x_or_z │ │ --- ┆ --- ┆ --- │ │ i64 ┆ i64 ┆ i64 │ ╞═════╪═════╪════════╡ │ 5 ┆ -9 ┆ -9 │ │ 6 ┆ 2 ┆ 6 │ │ 7 ┆ -1 ┆ -1 │ │ 4 ┆ 4 ┆ 4 │ │ 8 ┆ 8 ┆ 8 │ └─────┴─────┴────────┘