Skip to content

Concat two list variables

Source code

Description

Concat two list variables

Usage

<Expr>$list$concat(other)

Arguments

other Values to concat with. Can be an Expr or something coercible to an Expr.

Value

Expr

Examples

library("polars")

df = pl$DataFrame(
  a = list("a", "x"),
  b = list(c("b", "c"), c("y", "z"))
)
df$with_columns(
  conc_to_b = pl$col("a")$list$concat(pl$col("b")),
  conc_to_lit_str = pl$col("a")$list$concat(pl$lit("some string")),
  conc_to_lit_list = pl$col("a")$list$concat(pl$lit(list("hello", c("hello", "world"))))
)
#> shape: (2, 5)
#> ┌───────────┬────────────┬─────────────────┬──────────────────────┬─────────────────────────┐
#> │ a         ┆ b          ┆ conc_to_b       ┆ conc_to_lit_str      ┆ conc_to_lit_list        │
#> │ ---       ┆ ---        ┆ ---             ┆ ---                  ┆ ---                     │
#> │ list[str] ┆ list[str]  ┆ list[str]       ┆ list[str]            ┆ list[str]               │
#> ╞═══════════╪════════════╪═════════════════╪══════════════════════╪═════════════════════════╡
#> │ ["a"]     ┆ ["b", "c"] ┆ ["a", "b", "c"] ┆ ["a", "some string"] ┆ ["a", "hello"]          │
#> │ ["x"]     ┆ ["y", "z"] ┆ ["x", "y", "z"] ┆ ["x", "some string"] ┆ ["x", "hello", "world"] │
#> └───────────┴────────────┴─────────────────┴──────────────────────┴─────────────────────────┘