polars.format¶
- polars.format(fstring: str, *args: Union[polars.internals.expr.Expr, str]) polars.internals.expr.Expr ¶
String format utility for expressions
- Parameters
- fstring
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 │ └─────────────┘