polars.Expr.not_#
- Expr.not_() Expr[source]#
Method equivalent of bitwise “not” operator
~expr.This has the effect of negating logical boolean expressions, but operates bitwise on integers.
Examples
>>> df = pl.DataFrame( ... { ... "label": ["aa", "bb", "cc", "dd", "ee"], ... "valid": [True, False, None, False, True], ... "int_code": [1, 0, 2, None, -1], ... } ... )
Apply “not” to boolean expression (negates the value) and integer expression (operates bitwise):
>>> df.with_columns( ... not_valid=pl.col("valid").not_(), ... not_int_code=pl.col("int_code").not_(), ... ) shape: (5, 5) ┌───────┬───────┬──────────┬───────────┬──────────────┐ │ label ┆ valid ┆ int_code ┆ not_valid ┆ not_int_code │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ str ┆ bool ┆ i64 ┆ bool ┆ i64 │ ╞═══════╪═══════╪══════════╪═══════════╪══════════════╡ │ aa ┆ true ┆ 1 ┆ false ┆ -2 │ │ bb ┆ false ┆ 0 ┆ true ┆ -1 │ │ cc ┆ null ┆ 2 ┆ null ┆ -3 │ │ dd ┆ false ┆ null ┆ true ┆ null │ │ ee ┆ true ┆ -1 ┆ false ┆ 0 │ └───────┴───────┴──────────┴───────────┴──────────────┘