Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Polars · Function

pl.concat_str

Concatenates multiple columns or expressions horizontally into one string column. It can insert a separator, casts non-string inputs to String, and optionally skips null values.

How it works

Use pl.concat_str to combine several expressions horizontally into one string expression. Inputs are converted to strings when needed, and null handling is controlled by ignore_nulls.

Syntax

polars.concat_str(exprs: IntoExpr | Iterable[IntoExpr], *more_exprs: IntoExpr, separator: str = '', ignore_nulls: bool = False) → Expr

Parameters

NameTypeDescription
exprsIntoExpr | Iterable[IntoExpr]Columns to concatenate into a single string column. Accepts expression input. Strings are parsed as column names, other non-expression inputs are parsed as literals. Non-String columns are cast to String.
more_exprsIntoExprAdditional columns to concatenate into a single string column, specified as positional arguments.
separatorstr = ''String used to separate the values of each column.
ignore_nullsbool = FalseWhether to ignore null values; the default is False.

Returns

Expr

Key points

  • The function combines multiple expressions across each row and returns one string column.
  • Its documented complexity is linear in the amount of input data.
  • A string argument names a column; other plain values are treated as literals.
  • Numeric and other non-string inputs are converted to strings before joining.
  • separator controls the text placed between values contributed by adjacent expressions.
  • Set ignore_nulls to true when null entries should be omitted from the row-wise concatenation.

Common mistakes

  • The default ignore_nulls=False means any null in a row makes the resulting value null.

Example: Concatenate columns per row

import polars as pl

df = pl.DataFrame({"a": [1, 2, 3], "b": ["dogs", "cats", None], "c": ["play", "swim", "walk"]})
result = df.with_columns(
    pl.concat_str(
        [pl.col("a") * 2, pl.col("b"), pl.col("c")],
        separator=" ",
    ).alias("full_sentence")
)
print(result)

Builds one string expression per row from transformed and existing columns, separating values with spaces.

When to use it

Build composite labels

Create readable row-level labels from IDs, names, or categories.

Generate formatted text

Combine transformed numeric and text expressions into one sentence-like field.

Construct delimited identifiers

Assemble path, key, or identifier components with a chosen delimiter.

Interview questions

QWhat does pl.concat_str do?

It concatenates columns horizontally, producing one string value for each row. The operation runs in linear time.

Follow-up: How do numeric inputs behave? They are cast to String before concatenation.

QHow are inputs interpreted?

exprs is the primary iterable or expression input, while more_exprs accepts additional columns as positional arguments. Strings are interpreted as column names and other non-expression values as literals.

Follow-up: How would you include a fixed prefix? Pass a literal expression such as pl.lit("id-") alongside the column expressions.

QHow do separator and null handling affect output?

separator is inserted between values from each input expression. By default it is an empty string, so concatenation occurs without a delimiter.

Follow-up: What happens with a null when ignore_nulls is true? The null value is skipped rather than propagating to the row result.

  • polars.concat_list
  • polars.concat
  • polars.Expr.str.concat

Source: polars.concat_str — Polars documentation. Checked 2026-10-15.