简体   繁体   中英

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.

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() . 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)) . It makes the code simpler and clearer. If you also need the indexes for something, use enumerate() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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