daft.to_struct#
- to_struct(*inputs: daft.expressions.expressions.Expression | str) Expression [source]#
Converts multiple input expressions or column names into a struct.
Example
>>> import daft >>> from daft import col >>> df = daft.from_pydict({"a": [1, 2, 3], "b": ["a", "b", "c"]}) >>> df.select(daft.to_struct(col("a")*2, col("b"))).show() ╭───────────────────────────╮ │ struct │ │ --- │ │ Struct[a: Int64, b: Utf8] │ ╞═══════════════════════════╡ │ {a: 2, │ │ b: a, │ │ } │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ {a: 4, │ │ b: b, │ │ } │ ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤ │ {a: 6, │ │ b: c, │ │ } │ ╰───────────────────────────╯ (Showing first 3 of 3 rows)
- Parameters:
inputs – Expressions to be converted into struct fields.
- Returns:
An expression for a struct column with the input columns as its fields.