How do I merge 2 multi-index dataframes? I get the error below.
df1 cola_df1 colb_df1
Fruit 1/1/20 2 3
1/2/20 4 5
Apple 1/1/20 8 9
1/2/20 10 11
df2 cola_df2 colb_df2
Fruit 1/1/20 2 3
1/2/20 999 5
Apple 1/1/20 8 9
1/2/20 10 11
df1 cola_df1 colb_df1 cola_df2 colb_df2
Fruit 1/1/20 2 3 2 3
1/2/20 99 5 999 5
Apple 1/1/20 8 9 8 9
1/2/20 10 11 10 11
I tried the following:
pd.concat([df1, df2], keys=['x', 'y'], axis=1).swaplevel(0,1, axis=1).sort_index(axis=1)
cannot handle a non-unique multi-index