0

How do i concatenate data frames from a list called 'df_list' containing names of pandas dataframes? the list is generated through a looping process.

df_list = ['x_0', 'x_1', 'x_2', 'x_3']

xyz=pd.concat((x_0, x_1, x_2, x_3), axis=0)
xyz

I can always concatenate it like as above manually. However since the number of dataframes can increase or decrease in an automated process. How do i dynamically use this list with concat function?

This doesnt work => xyz=pd.concat((df_list ), axis=0)

Tried converting df_list to series but that also doesnt work.

I am a beginner. any help is appreciated.

大陸北方網友
  • 3,696
  • 3
  • 12
  • 37
tiwar
  • 1
  • Use `xyz=pd.concat(df_list , axis=0)` – jezrael Oct 16 '20 at 09:09
  • this isnt working. I believe since it is stored as string in the df_list. TypeError: cannot concatenate object of type ''; only Series and DataFrame objs are valid – tiwar Oct 16 '20 at 10:51
  • I see, you need `df_list = [x_0, x_1, x_2, x_3]`, list of DataFrames, not list of strings – jezrael Oct 16 '20 at 10:52
  • yes and i am not able to figure out how to achieve this df_list = [x_0, x_1, x_2, x_3] – tiwar Oct 16 '20 at 10:54
  • Use `xyz=pd.concat(df_list , axis=0)` – jezrael Oct 16 '20 at 10:55
  • Error mean `df_list = ['x_0', 'x_1', 'x_2', 'x_3']` are not DataFrames, by strings, so expected. – jezrael Oct 16 '20 at 10:56
  • xyz=pd.concat(df_list , axis=0) this is not working How to convert df_list = ['x_0', 'x_1', 'x_2', 'x_3'] to df_list = [x_0, x_1, x_2, x_3] ? df_list is dynamically generated through a loop process. and x_0, x_1 are dataframes. Since it is part of list. the names are in string format. Btw i see question has been wrongly closed by stack overflow.. how do i reopen. – tiwar Oct 16 '20 at 11:03

0 Answers0