Skip to content
Advertisement

How to create a Pandas DataFrame from dictionary of dataframes?

I have a dictionary that is a list of dataframes that have all the same columns and data structure. I am wanting to essentially ‘union’ all of these into a single dataframe again, where the dictionary keys are converted into another column: df_list{}

JavaScript

…and so on

but am wanting:

JavaScript

I tried using pd.DataFrame.from_dict() but either I am not using it right or I need something else..

JavaScript

but get: ValueError: If using all scalar values, you must pass an index

when I try passing the index, I get one column back vs a dataframe.

Advertisement

Answer

This should do it:

JavaScript

Alternatively, we can also do this in one line with:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement