在相同索引上将3D列表转换为 pandas 单个数据框 [英] Converting 3d list into pandas single dataframe on same index
本文介绍了在相同索引上将3D列表转换为 pandas 单个数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的列表l
具有形状np.array(l).shape (100,15,1)
它具有100个数据帧,每个df包含15行和1列.索引是相同的,只是列表的每个df中的排序是不同的.
我想解压缩列表l:
My list l
has shape np.array(l).shape (100,15,1)
It has 100 dataframes with each df having 15 rows and 1 column. The index are same, just the sorting is different in each df of list.
I want to unzip the list l:
l[0] = Rank l[31] = Rank
A1 1 A5 1
A2 2 A1 2
A3 3 A8 3
A4 4.. till 15 A3 4 .... also till 15
我想要这个3-d列表l
中的单个数据帧,如下所示:
df=
(15,100)
I want a single dataframe from this 3-d list l
something like this:
df=
(15,100)
0 1 2
A1 1 2 3
A2 2 3 2
A3 3 6 1
A4 4 4 4
A5 5 8 6 .. till 100 columns and for all 15 indices
基本上,一个具有所有排名列表的数据框只能显示在同一索引上.
Basically, a dataframe with all ranking lists to be shown on same index only.
推荐答案
使用 concat
,其中axis=1
和ignore_index=True
是range
默认的新列:
Use concat
with axis=1
and ignore_index=True
for default new columns by range
:
df = pd.concat(l, axis=1, ignore_index=True)
print (df)
0 1
A1 1.0 2.0
A2 2.0 NaN
A3 3.0 4.0
A4 4.0 NaN
A5 NaN 1.0
A8 NaN 3.0
这篇关于在相同索引上将3D列表转换为 pandas 单个数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文