简体   繁体   English

Python将特定列表的列表连接到数据框

[英]Python concating lists of specific list to dataframe

I have a list of lists of dataframes.我有一个数据框列表列表。

Biglist = [[dfA1, dfB11,dfB12][dfA2, dfB21,dfB22][dfA3, dfB31,dfB32][dfA4, dfB41,dfB42]]

I want to create a data frame of A's from all sublists in the above list.我想从上面列表中的所有子列表创建一个 A 的数据框。

My expected output我的预期输出

df_A = concating dfA1 to dfA4

My present code我现在的代码

df_A = [pd.concat(Biglist[i][0],axis=1) for i in range(0,len(Biglist[i]),1)] 

My present output我现在的输出

TypeError: first argument must be an iterable of pandas objects, you passed an object of type "DataFrame"

You need to put the iterator in the first argument to pd.concat() .您需要将迭代器放在pd.concat()的第一个参数中。 Also, it doesn't need to be inside another list.此外,它不需要在另一个列表中。

df_A = pd.concat((l[0] for l in BigList), axis=0)

I also recommend you get used to using for var in listname rather than for i in range(len(listname)) .我还建议您习惯于for var in listname使用for var in listname而不是for i in range(len(listname)) It makes the code simpler and clearer.它使代码更简单、更清晰。 If you also need the indexes for something, use enumerate() .如果您还需要某些东西的索引,请使用enumerate()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM