I have a nested list like this
a=[ [[12,23],[31,41]], [[53,68],[77,87]] ]
and I'd like to create a pandas data frame like this
id1 id2 c2 c3
1 1 12 31
1 2 53 77
2 1 23 41
2 2 68 87
My idea was to do this:
ids = {'id1':[1,1,2,2],'id2':[1,2,1,2]}
df1 = pd.DataFrame(ids)
L = [[t[idx] for t in l] for idx in [0,1] for l in a]
df2 = pd.DataFrame(L, columns=['c1','c2'])
pd.concat([df1,df2], axis=1)
Is there a way to achieve the same result without so many commands?