tabsdata.tableframe.lazyframe.frame.TableFrame.unnest#

TableFrame.unnest(columns: td_typing.ColumnNameOrSelector | Collection[td_typing.ColumnNameOrSelector], *more_columns: td_typing.ColumnNameOrSelector) TableFrame[source]#

Expand one or more struct columns so that each field within the struct becomes a separate column in the TableFrame.

The resulting TableFrame will place these new columns in the same position as the original struct column, effectively replacing it. This makes it easier to work directly with the inner fields as standard columns.

Parameters:
  • columns – Name of the struct column(s) to expand.

  • more_columns – Additional struct columns to expand, provided as positional arguments.

Example:

>>> import tabsdata as td
>>>
>>> tf = td.TableFrame({
...     "id": [1, 2],
...     "info": [
...         {"name": "Alice", "age": 30},
...         {"name": "Bob", "age": None},
...     ],
...     "status": ["active", "inactive"],
... })
>>>
>>> tf
>>>
┌─────┬───────────────┬───────────┐
│ id  ┆ info          ┆ status    │
│ --- ┆ ---           ┆ ---       │
│ i64 ┆ struct[2]     ┆ str       │
╞═════╪═══════════════╪═══════════╡
│ 1   ┆ {"Alice",30}  ┆ active    │
│ 2   ┆ {"Bob",null}  ┆ inactive  │
└─────┴───────────────┴───────────┘
>>>
>>> tf.unnest("info")
>>>
┌─────┬───────┬──────┬───────────┐
│ id  ┆ name  ┆ age  ┆ status    │
│ --- ┆ ---   ┆ ---  ┆ ---       │
│ i64 ┆ str   ┆ i64  ┆ str       │
╞═════╪═══════╪══════╪═══════════╡
│ 1   ┆ Alice ┆ 30   ┆ active    │
│ 2   ┆ Bob   ┆ null ┆ inactive  │
└─────┴───────┴──────┴───────────┘