Method: Polars::NameExpr#map

Defined in:
lib/polars/name_expr.rb

#map(&function) ⇒ Expr

Rename the output of an expression by mapping a function over the root name.

Examples:

Remove a common suffix and convert to lower case.

df = Polars::DataFrame.new(
  {
    "A_reverse" => [3, 2, 1],
    "B_reverse" => ["z", "y", "x"]
  }
)
df.with_columns(
  Polars.all.reverse.name.map { |c| c.delete_suffix("_reverse").downcase }
)
# =>
# shape: (3, 4)
# ┌───────────┬───────────┬─────┬─────┐
# │ A_reverse ┆ B_reverse ┆ a   ┆ b   │
# │ ---       ┆ ---       ┆ --- ┆ --- │
# │ i64       ┆ str       ┆ i64 ┆ str │
# ╞═══════════╪═══════════╪═════╪═════╡
# │ 3         ┆ z         ┆ 1   ┆ x   │
# │ 2         ┆ y         ┆ 2   ┆ y   │
# │ 1         ┆ x         ┆ 3   ┆ z   │
# └───────────┴───────────┴─────┴─────┘

Returns:



80
81
82
# File 'lib/polars/name_expr.rb', line 80

def map(&function)
  Utils.wrap_expr(_rbexpr.name_map(function))
end