maxframe.liteframe.LiteFrame.explode#

LiteFrame.explode(column)#

Explode list column(s) into multiple rows.

LiteFrame analogue of pandas.DataFrame.explode: each list-like value in column is expanded to one row per element; the other columns are broadcast (repeated) across the expanded rows and keep their original order. An empty list or missing value produces a single NA row.

When multiple columns are given they are exploded in lock-step (one output row per element index across all of them), matching pandas; their element counts must agree per row. The expansion is a single flat_apply.

Parameters:

column (str or list of str) – The list column(s) to explode.

Returns:

A new LiteFrame with the same columns; each exploded column now holds its element dtype (the list’s value_type).

Return type:

LiteFrame

See also

flat_apply

Apply a function per row, expanding to 0-N rows.

LiteFrame.list.flatten

Flatten a list column.

Examples

>>> import maxframe.liteframe as mlf
>>> import pandas as pd
>>> import pyarrow as pa
>>> from maxframe.utils import wrap_arrow_dtype
>>> _list = wrap_arrow_dtype(pa.list_(pa.int64()))
>>> raw = pd.DataFrame({'b': [4, 5]})
>>> raw['a'] = pd.Series([[1, 2], [3]]).astype(_list)
>>> lf = mlf.LiteFrame(raw)
>>> result = lf.explode('a')
>>> result.execute()
   b  a
0  4  1
0  4  2
1  5  3