I have multiple dataframes df1, df2 ,df3 etc to df10. The dataframe has 135 columns. each look like this:
time | a | b | c | d | e | f | g |
---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
I wanted to arrange them in one data frame and stack them together side by side but having their df name as the header. Meaning one heading df1 having all those columns names( time,a,b...) and their value under it and so on.Seeing this example here Constructing 3D Pandas DataFrame I tried following codes
list1=['df1', 'df2', 'df3', 'df4', 'df5','df6', 'df7', 'df8', 'df9',
'df10']
list2=[]
for df in list1:
for i in range(135):
list2.append(df)
A=np.array(list2)
B = np.array([df1.columns]*10)
C=pd.concat([df1,df2,df3,df4,df5,df6,df7,df8,df9,df10], axis=1)
C=C.values.tolist()
C=np.array(C)
df = pd.DataFrame(data=C.T, columns=pd.MultiIndex.from_tuples(zip(A,B)))
print(df)
But each time I am having an error
TypeError: unhashable type: 'numpy.ndarray'
I have a column time: where the time are in hhmm format. 01:00,01:01 so on. I tried dropping the column from the data frames but getting same error. How could I fix this? Can anyone help?