string_split
laktory.narwhals_ext.expr.string_split
¤
FUNCTION | DESCRIPTION |
---|---|
string_split |
Get substring using separator |
string_split(self, pattern, key)
¤
Get substring using separator pattern
.
PARAMETER | DESCRIPTION |
---|---|
pattern
|
String or regular expression to split on. If not specified, split on whitespace.
TYPE:
|
key
|
Split index to return
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Expr
|
Result |
Examples:
```py¤
import polars as pl¤
¤
import laktory as lk # noqa: F401¤
¤
df = nw.from_native(pl.DataFrame({"x": ["price_close"]}))¤
¤
df = df.with_columns(y=nw.col("x").laktory.string_split(pattern="_", key=1))¤
print(df.to_native().glimpse(return_as_string=True))¤
'''¤
Rows: 1¤
Columns: 2¤
$ x 'price_close'¤
$ y 'close'¤
'''¤
```
Source code in laktory/narwhals_ext/expr/string_split.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
|