Gets the n (from nchars) left-most characters of each string.
Returns:
| Name | Type | Description |
Expression | Expression | a String expression which is the n left-most characters of self |
Examples:
| >>> import daft
>>> from daft.functions import left
>>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
>>> df = df.select(left(df["x"], 4))
>>> df.show()
|
╭────────╮
│ x │
│ --- │
│ String │
╞════════╡
│ daft │
├╌╌╌╌╌╌╌╌┤
│ quer │
├╌╌╌╌╌╌╌╌┤
│ engi │
╰────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735 | def left(expr: Expression, nchars: int | Expression) -> Expression:
"""Gets the n (from nchars) left-most characters of each string.
Returns:
Expression: a String expression which is the `n` left-most characters of `self`
Examples:
>>> import daft
>>> from daft.functions import left
>>> df = daft.from_pydict({"x": ["daft", "query", "engine"]})
>>> df = df.select(left(df["x"], 4))
>>> df.show()
╭────────╮
│ x │
│ --- │
│ String │
╞════════╡
│ daft │
├╌╌╌╌╌╌╌╌┤
│ quer │
├╌╌╌╌╌╌╌╌┤
│ engi │
╰────────╯
<BLANKLINE>
(Showing first 3 of 3 rows)
"""
return Expression._call_builtin_scalar_fn("left", expr, nchars)
|