acidplyr.unlist2

acidplyr.unlist2(x: dict[str, DataFrame], name_col: str = 'name', rowname_col: str = 'rowname') DataFrame

Unlist a dictionary of DataFrames into a single DataFrame.

Unlike pd.concat, this adds explicit name_col and rowname_col columns instead of using a MultiIndex.

Parameters:
  • x (dict[str, pd.DataFrame]) – Named dictionary of DataFrames.

  • name_col (str, optional) – Column name for the dictionary keys.

  • rowname_col (str, optional) – Column name for the original row indices.

Returns:

Concatenated DataFrame with name_col and rowname_col prepended.

Return type:

pd.DataFrame

Examples

>>> import pandas as pd
>>> d = {"a": pd.DataFrame({"x": [1, 2]}), "b": pd.DataFrame({"x": [3]})}
>>> unlist2(d).to_dict("list")
{'name': ['a', 'a', 'b'], 'rowname': ['0', '1', '0'], 'x': [1, 2, 3]}