Method: Polars::StringExpr#join

Defined in:
lib/polars/string_expr.rb

#join(delimiter = nil, ignore_nulls: true) ⇒ Expr

Vertically concat the values in the Series to a single string value.

Examples:

df = Polars::DataFrame.new({"foo" => [1, nil, 2]})
df.select(Polars.col("foo").str.join("-"))
# =>
# shape: (1, 1)
# ┌─────┐
# │ foo │
# │ --- │
# │ str │
# ╞═════╡
# │ 1-2 │
# └─────┘
df = Polars::DataFrame.new({"foo" => [1, nil, 2]})
df.select(Polars.col("foo").str.join("-", ignore_nulls: false))
# =>
# shape: (1, 1)
# ┌──────┐
# │ foo  │
# │ ---  │
# │ str  │
# ╞══════╡
# │ null │
# └──────┘

Parameters:

  • (defaults to: nil)

    The delimiter to insert between consecutive string values.

  • (defaults to: true)

    Ignore null values (default).

Returns:



381
382
383
384
385
386
387
388
389
# File 'lib/polars/string_expr.rb', line 381

def join(delimiter = nil, ignore_nulls: true)
  # TODO update
  if delimiter.nil?
    warn "The default `delimiter` for `join` method will change from `-` to empty string in a future version"
    delimiter = "-"
  end

  Utils.wrap_expr(_rbexpr.str_join(delimiter, ignore_nulls))
end