I try to obtain a 3D dataframe from 2 dataframes that have the same shape. If we take the below script as the example, I want to create a 3D dataframe that have 2 rows (a and b), 3 columns (A, B and C), and 2 items (df1 and df2). And also to be clear, I tried to explain my problem with a figure.
import pandas as pd
df1 = pd.DataFrame([[1, 2, 11], [3, 4, 12]], columns=['A', 'B', 'C'], index=['a', 'b'])
df2 = pd.DataFrame([[5, 6, 13], [7, 8, 14]], columns=['A', 'B', 'C'], index=['a', 'b'])
I saw related questions and tried some of them. I have tried to use pd.MultiIndex, but I obtained error as “ValueError: Length of levels and labels must be the same.”
Is there any way to obtain a 3D dataframe as described in below figure?
Thanks.





