polars.format#

polars.format(f_string: str, *args: Expr | str) Expr[source]#

Format expressions as a string.

Parameters:
f_string

A string that with placeholders. For example: “hello_{}” or “{}_world

args

Expression(s) that fill the placeholders

Examples

>>> df = pl.DataFrame(
...     {
...         "a": ["a", "b", "c"],
...         "b": [1, 2, 3],
...     }
... )
>>> df.select(
...     [
...         pl.format("foo_{}_bar_{}", pl.col("a"), "b").alias("fmt"),
...     ]
... )
shape: (3, 1)
┌─────────────┐
│ fmt         │
│ ---         │
│ str         │
╞═════════════╡
│ foo_a_bar_1 │
│ foo_b_bar_2 │
│ foo_c_bar_3 │
└─────────────┘