pack_lists

Contents

pack_lists#

pack_lists(df: DataFrame, name: str | None = None, *, validate: bool = True) NestedSeries[source]#

Make a series of arrow structures from a dataframe with nested arrays.

For the input dataframe with repeated indexes, make a pandas.Series, where each original column is replaced by a structure of lists. The dtype of the column is nested_pandas.NestedDtype with the corresponding pyarrow type. The index of the output series is the unique index of the input dataframe. The Series has .nest accessor, see nested_pandas.series.accessor.NestSeriesAccessor() for details.

For every row, all the nested array (aka pyarrow list) lengths must be the same.

Parameters:
  • df (pd.DataFrame) – Input dataframe, with pyarrow list-arrays.

  • name (str, optional) – Name of the NestedSeries.

  • validate (bool, default True) – Whether to validate the input dataframe.

Returns:

Output series, with unique indexes.

Return type:

NestedSeries

See also

nested_pandas.series.accessor.NestSeriesAccessor

The accessor for the output series.

nested_pandas.series.dtype.NestedDtype

The dtype of the output series.

nested_pandas.series.packer.pack_flat

Pack a “flat” dataframe with repeated indexes.