explode#
- NestedFrame.explode(column: Hashable | Sequence[Hashable], ignore_index: bool = False)[source]#
Transform each element of a list-like base column to a row, replicating index values.
- Parameters:
column (IndexLabel) – Column(s) to explode. For multiple columns, specify a non-empty list with each element be str or tuple, and all specified columns their list-like data on same row of the frame must have matching length.
ignore_index (bool, default False) – If True, the resulting index will be labeled 0, 1, …, n - 1.
- Returns:
Exploded lists and to rows of the subset columns; index will be duplicated for these rows.
- Return type:
- Raises:
ValueError – It raises if: 1) columns of the frame are not unique, 2) specified columns to explode is an empty list, 3) specified columns to explode do not have matching counts of elements rowwise in the frame.
See also
Examples
>>> from nested_pandas.datasets.generation import generate_data >>> nf = generate_data(3,3, seed=1)
>>> nf_explode = nf.explode(column="nested") >>> nf_explode a b t flux flux_error band 0 0.417022 0.604665 3.725204 67.046751 1.0 g 0 0.417022 0.604665 10.776335 14.038694 1.0 g 0 0.417022 0.604665 4.089045 96.826158 1.0 g 1 0.720324 0.293512 6.911215 41.73048 1.0 r 1 0.720324 0.293512 8.38389 19.810149 1.0 r 1 0.720324 0.293512 17.562349 31.342418 1.0 g 2 0.000114 0.184677 7.935349 55.868983 1.0 r 2 0.000114 0.184677 13.70439 80.074457 1.0 r 2 0.000114 0.184677 0.547752 69.232262 1.0 g