polars.internals.expr.ExprStringNameSpace.split_exact

ExprStringNameSpace.split_exact(by: str, n: int, inclusive: bool = False) polars.internals.expr.Expr

Split the string by a substring into a struct of n fields. The return type will by of type Struct<Utf8>

If it cannot make n splits, the remaiming field elements will be null

Parameters
by

substring

n

Number of splits to make

inclusive

Include the split character/string in the results

Examples

>>> (
...     pl.DataFrame({"x": ["a_1", None, "c", "d_4"]}).select(
...         [
...             pl.col("x").str.split_exact("_", 1).alias("fields"),
...         ]
...     )
... )
shape: (4, 1)
┌───────────────────────────────────────────┐
│ fields                                    │
│ ---                                       │
│ struct[2]{'field_0': str, 'field_1': str} │
╞═══════════════════════════════════════════╡
│ {"a","1"}                                 │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ {null,null}                               │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ {"c",null}                                │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ {"d","4"}                                 │
└───────────────────────────────────────────┘