简体   繁体   English

将列表中每个 DataFrame 的每一列放入大列表中的自己的列表中

[英]Making each column of each DataFrame in a list into its own list within a big list

Task Description任务描述

If I have a list of DataFrames in say a_list and each list looked like the following:如果我在a_list有一个 DataFrame 列表,并且每个列表如下所示:

    1  2  3
a   x  x  x
b   y  y  y 
c   z  z  z

I am interested in making each column of each DataFrame in a_list into its own list.我有兴趣将a_list中每个 DataFrame 的每一列都放入自己的列表中。

So say b_list[0] would be所以说b_list[0]将是

    1  
a   x 
b   y  
c   z

b_list[1] would be b_list[1]将是

    2  
a   x 
b   y  
c   z

etc.等等。

I currently have around 150 DataFrames in a list with each having 30+ columns.我目前在一个列表中有大约 150 个数据帧,每个数据帧有 30 多列。 So the desired list would have around b_list[4500] Any help with this would be awesome!所以所需的列表大约有b_list[4500]任何有关此的帮助都会很棒!

Try this:尝试这个:

b_list = []
for df in a_list:
    for col in df.columns:
        b_list.append(df[[col]])

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

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