polars.Expr.struct.unnest#

Expr.struct.unnest() Expr[source]#

Expand the struct into its individual fields.

Alias for Expr.struct.field("*").

>>> df = pl.DataFrame(
...     {
...         "aaa": [1, 2],
...         "bbb": ["ab", "cd"],
...         "ccc": [True, None],
...         "ddd": [[1, 2], [3]],
...     }
... ).select(pl.struct("aaa", "bbb", "ccc", "ddd").alias("struct_col"))
>>> df
shape: (2, 1)
┌──────────────────────┐
│ struct_col           │
│ ---                  │
│ struct[4]            │
╞══════════════════════╡
│ {1,"ab",true,[1, 2]} │
│ {2,"cd",null,[3]}    │
└──────────────────────┘
>>> df.select(pl.col("struct_col").struct.unnest())
shape: (2, 4)
┌─────┬─────┬──────┬───────────┐
│ aaa ┆ bbb ┆ ccc  ┆ ddd       │
│ --- ┆ --- ┆ ---  ┆ ---       │
│ i64 ┆ str ┆ bool ┆ list[i64] │
╞═════╪═════╪══════╪═══════════╡
│ 1   ┆ ab  ┆ true ┆ [1, 2]    │
│ 2   ┆ cd  ┆ null ┆ [3]       │
└─────┴─────┴──────┴───────────┘