nest_lists

nest_lists#

NestedFrame.nest_lists(columns: list[str], name: str) NestedFrame[source]#

Creates a new NestedFrame where the specified list-value columns are packed into a nested column.

Parameters:
  • columns (list[str]) – The list-value columns that should be packed into a nested column. All columns in the list will attempt to be packed into a single nested column with the name provided in nested_name.

  • name (str) – The column name of the new nested column which we will pack the list-value columns into. This column will be added to the NestedFrame.

Returns:

A new NestedFrame with the added nested columns

Return type:

NestedFrame

Examples

>>> import nested_pandas as npd
>>> nf = npd.NestedFrame({"c":[1,2,3], "d":[2,4,6],
...                   "e":[[1,2,3], [4,5,6], [7,8,9]]},
...                   index=[0,1,2])
>>> nf.nest_lists(columns=["e"], name="nested")
   c  d                nested
0  1  2  [{e: 1}; …] (3 rows)
1  2  4  [{e: 4}; …] (3 rows)
2  3  6  [{e: 7}; …] (3 rows)