问题
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
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.
回答1:
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
来源:https://stackoverflow.com/questions/64782474/converting-3d-list-into-pandas-single-dataframe-on-same-index