Select all boolean columns.
df = Polars::DataFrame.new({"n" => 1..4}).with_columns(n_even: Polars.col("n") % 2 == 0) # => # shape: (4, 2) # ┌─────┬────────┐ # │ n ┆ n_even │ # │ --- ┆ --- │ # │ i64 ┆ bool │ # ╞═════╪════════╡ # │ 1 ┆ false │ # │ 2 ┆ true │ # │ 3 ┆ false │ # │ 4 ┆ true │ # └─────┴────────┘
Select and invert boolean columns:
df.with_columns(is_odd: Polars.cs.boolean.not_) # => # shape: (4, 3) # ┌─────┬────────┬────────┐ # │ n ┆ n_even ┆ is_odd │ # │ --- ┆ --- ┆ --- │ # │ i64 ┆ bool ┆ bool │ # ╞═════╪════════╪════════╡ # │ 1 ┆ false ┆ true │ # │ 2 ┆ true ┆ false │ # │ 3 ┆ false ┆ true │ # │ 4 ┆ true ┆ false │ # └─────┴────────┴────────┘
Select all columns except for those that are boolean:
df.select(~Polars.cs.boolean) # => # shape: (4, 1) # ┌─────┐ # │ n │ # │ --- │ # │ i64 │ # ╞═════╡ # │ 1 │ # │ 2 │ # │ 3 │ # │ 4 │ # └─────┘
Returns:
347 348 349
# File 'lib/polars/selectors.rb', line 347 def self.boolean by_dtype([Boolean]) end