Split the string by a substring
Description
Split the string by a substring
Usage
<Expr>$str$split(by, inclusive = FALSE)
Arguments
by
|
Substring to split by. Can be an Expr. |
inclusive
|
If TRUE , include the split character/string in the results.
|
Value
List of String type
Examples
library("polars")
df = pl$DataFrame(s = c("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"] │
#> └───────────────────────┘
#> shape: (3, 2)
#> ┌─────────────┬─────┐
#> │ s ┆ by │
#> │ --- ┆ --- │
#> │ str ┆ str │
#> ╞═════════════╪═════╡
#> │ foo^bar ┆ _ │
#> │ foo_bar ┆ _ │
#> │ foo*bar*baz ┆ * │
#> └─────────────┴─────┘
#> shape: (3, 1)
#> ┌───────────────────────┐
#> │ split │
#> │ --- │
#> │ list[str] │
#> ╞═══════════════════════╡
#> │ ["foo^bar"] │
#> │ ["foo", "bar"] │
#> │ ["foo", "bar", "baz"] │
#> └───────────────────────┘