Skip to content
Advertisement

What is the best way to combine dataframes that have been created through a for loop?

I am trying to combine dataframes with 2 columns into a single dataframe. The initial dataframes are generated through a for loop and stored in a list. I am having trouble getting the data from the list of dataframes into a single dataframe. Right now when I run my code, it treats each full dataframe as a row.

JavaScript

when I run this block of code I get a list of dataframes that have 2 columns. When I try to convert df_export to a dataframe, it ends up with 12 rows (the number of categories in category_list). I tried:

JavaScript

but the result was:

JavaScript

I would like to have a single dataframe with 2 columns, [Category, Value] that includes the values of all 12 categories generated in the for loop.

Advertisement

Answer

You can use pd.concat to merge a list of DataFrames into a single big DataFrame.

JavaScript

you can manipulate it to your proper demande

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