Skip to content

daft.functions.capitalize#

capitalize #

capitalize(expr: Expression) -> Expression

Capitalize a UTF-8 string.

Returns:

Name Type Description
Expression Expression

a String expression which is self uppercased with the first character and lowercased the rest

Examples:

1
2
3
4
5
>>> import daft
>>> from daft.functions import capitalize
>>> df = daft.from_pydict({"x": ["foo", "bar", "baz"]})
>>> df = df.select(capitalize(df["x"]))
>>> df.show()
╭────────╮
│ x      │
│ ---    │
│ String │
╞════════╡
│ Foo    │
├╌╌╌╌╌╌╌╌┤
│ Bar    │
├╌╌╌╌╌╌╌╌┤
│ Baz    │
╰────────╯
(Showing first 3 of 3 rows)
Source code in daft/functions/str.py
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
def capitalize(expr: Expression) -> Expression:
    """Capitalize a UTF-8 string.

    Returns:
        Expression: a String expression which is `self` uppercased with the first character and lowercased the rest

    Examples:
        >>> import daft
        >>> from daft.functions import capitalize
        >>> df = daft.from_pydict({"x": ["foo", "bar", "baz"]})
        >>> df = df.select(capitalize(df["x"]))
        >>> df.show()
        ╭────────╮
        │ x      │
        │ ---    │
        │ String │
        ╞════════╡
        │ Foo    │
        ├╌╌╌╌╌╌╌╌┤
        │ Bar    │
        ├╌╌╌╌╌╌╌╌┤
        │ Baz    │
        ╰────────╯
        <BLANKLINE>
        (Showing first 3 of 3 rows)

    """
    return Expression._call_builtin_scalar_fn("capitalize", expr)