Given a list of df
, the objective is to save all df
in single page long format.
Each of the df
is make up from 3 level columns index. The first level is unique ('theme1' and 'theme2') for each of the df
. Whereas, the second ('level2) and third (A,B,C) level is similar for all 'df`.
In the code snippet below,
import pandas as pd
df1 = pd.DataFrame({'A': [11, 21, 31],
'B': [12, 22, 32],
'C': [13, 23, 33]},
index=['ONE', 'TWO', 'THREE'])
df2 = pd.DataFrame({'A': [111, 211, 311],
'B': [121, 221, 321],
'C': [131, 231, 331]},
index=['ONE', 'TWO', 'THREE'])
df1.columns = pd.MultiIndex.from_product([['theme1'],['level2'],df1.columns ])
df2.columns = pd.MultiIndex.from_product([['theme2'],['level2'],df2.columns ])
list_df=[df1,df2]
df_all=pd.concat(list_df,axis=1)
df_all.to_excel('df_all1.xlsx')
A single page wide format is produced
But, I wonder how to make a single page long format as depicted below
p.s. Long format allow easy excel vertical scrolling