pandas_ts.packer

Module for converting between “flat” and “list” and “ts” representations

TODO: mask support TODO: multi-index support

Module Contents

Functions

pack_flat(→ pandas.Series)

Make a structure of lists representation of a "flat" dataframe.

pack_dfs(→ pandas.Series)

Pack a sequence of "flat" dataframes into a "nested" series.

pack_lists(→ pandas.Series)

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

pack_flat(df: pandas.DataFrame, name: str | None = None) pandas.Series[source]

Make a structure of lists representation of a “flat” dataframe.

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 pandas_ts.TsDtype with the corresponding pyarrow type. The index of the output series is the unique index of the input dataframe. The Series has .ts accessor, see pandas_ts.ts_accessor.TsAccessor for details.

Parameters:
  • df (pd.DataFrame) – Input dataframe, with repeated indexes.

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

Returns:

Output series, with unique indexes.

Return type:

pd.Series

See also

pandas_ts.ts_accessor.TsAccessor

The accessor for the output series.

pandas_ts.TsDtype

The dtype of the output series.

pandas_ts.packer.pack_lists

Pack a dataframe of nested arrays.

pack_dfs(dfs: collections.abc.Sequence[pandas.DataFrame], index: object = None, name: str | None = None) pandas.Series[source]

Pack a sequence of “flat” dataframes into a “nested” series.

Parameters:
  • dfs (Sequence[pd.DataFrame]) – Input sequence of dataframes.

  • index (pd.Index, optional) – Index of the output series.

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

Returns:

Output series.

Return type:

pd.Series

pack_lists(df: pandas.DataFrame, name: str | None = None, *, validate: bool = True) pandas.Series[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 pandas_ts.TsDtype with the corresponding pyarrow type. The index of the output series is the unique index of the input dataframe. The Series has .ts accessor, see pandas_ts.ts_accessor.TsAccessor 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 pd.Series.

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

Returns:

Output series, with unique indexes.

Return type:

pd.Series

See also

pandas_ts.ts_accessor.TsAccessor

The accessor for the output series.

pandas_ts.TsDtype

The dtype of the output series.

pandas_ts.packer.pack_flat

Pack a “flat” dataframe with repeated indexes.