0

Say I have a list of lists of dfs in the form like this

ls = [[df1, df2, df3], [df4, df5, df6], [df7, df8, df9]]

I want to somehow concatenate along columns so that the resulting list is like this

ls = [pd.concat([df1, df4, df7], axis=0),
      pd.concat([df2, df5, df8], axis=0),
      pd.concat([df3, df6, df9], axis=0)]

I'm not entirely sure how to approach this. I guess a naive way could be to use 2 for loops and iterate over columns, making a new list, and the using pd.concat to make one? But is there a better way then that using maybe numpy arrays or some function I do not know about?

wjandrea
  • 28,235
  • 9
  • 60
  • 81

0 Answers0