Function format

  • String format utility for expressions Note: strings will be interpolated as col(<value>). if you want a literal string, use lit(<value>)

    Parameters

    • strings: string | TemplateStringsArray
    • Rest ...expr: ExprOrString[]

    Returns pl.Expr

    Example

    > 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
    └─────────────┘

    // You can use format as tag function as well
    > pl.format("foo_{}_bar_{}", pl.col("a"), "b") // is the same as
    > pl.format`foo_${pl.col("a")}_bar_${"b"}`