polars.Expr.str.split#

Expr.str.split(by: str, inclusive: bool = False) Expr[source]#

Split the string by a substring.

Parameters:
by

Substring to split by.

inclusive

If True, include the split character/string in the results.

Returns:
List of Utf8 type

Examples

>>> df = pl.DataFrame({"s": ["foo bar", "foo-bar", "foo bar baz"]})
>>> df.select(pl.col("s").str.split(by=" "))
shape: (3, 1)
┌───────────────────────┐
│ s                     │
│ ---                   │
│ list[str]             │
╞═══════════════════════╡
│ ["foo", "bar"]        │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ ["foo-bar"]           │
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
│ ["foo", "bar", "baz"] │
└───────────────────────┘