NestedFrame.split#
- NestedFrame.split(nested_col: str, by: str, values=None, drop_by_col: bool = False, drop_nested: bool = False) NestedFrame[source]#
Split a nested column into multiple nested columns by a categorical sub-column.
- Parameters:
nested_col (str) – The name of the nested column to split.
by (str) – The name of the sub-column within nested_col to split on.
values (list or str or None, optional) – The specific values to split on. If None, all unique values are used. If a string is provided, it is iterated as a list of characters.
drop_by_col (bool, default False) – If True, the sub-column specified by by is dropped from each new nested column.
drop_nested (bool, default False) – If True, the original nested column is dropped from the result.
- Returns:
A new NestedFrame with one new nested column per unique value in by, named
{nested_col}_{value}.- Return type:
Examples
>>> from nested_pandas.datasets.generation import generate_data >>> nf = generate_data(5, 5, seed=1) >>> nf.split("nested", by="band")[["a", "b", "nested_r"]]
a b nested_r
0 0.417022 0.184677 [{t: 8.38389, flux: 31.551563, band: ‘r’}; …] (2 rows) 1 0.720324 0.372520 [{t: 19.365232, flux: 90.85955, band: ‘r’}; …] (2 rows) 2 0.000114 0.691121 [{t: 11.173797, flux: 28.044399, band: ‘r’}; …] (3 rows) 3 0.302333 0.793535 [{t: 2.807739, flux: 78.927933, band: ‘r’}] 4 0.146756 1.077633 [{t: 17.527783, flux: 13.002857, band: ‘r’}; …] (2 rows)