Writing Multiple Excel Sheets from Pandas

import pandas as pd
import numpy as np

Extra import statement

from pandas import ExcelWriter

Make fake data

df = pd.DataFrame(np.random.rand(10, 4), columns=['A','B','C','D'])
df
A B C D
0 0.554371 0.777338 0.642583 0.138115
1 0.613897 0.165685 0.386274 0.066028
2 0.275948 0.288185 0.574445 0.826506
3 0.276886 0.865333 0.054961 0.167877
4 0.157003 0.740550 0.537578 0.245217
5 0.362938 0.832686 0.530044 0.342483
6 0.659269 0.669603 0.889892 0.899236
7 0.247132 0.760786 0.714053 0.285258
8 0.791949 0.565014 0.067511 0.709892
9 0.445282 0.106912 0.673259 0.412615

Write to File

filepath = 'sample-files/writing-multiple-sheets.xlsx'
with ExcelWriter(filepath) as writer:
    df[['A']].to_excel(writer,
                       sheet_name='A')
    # Or, iteratively:
    for col in ['B','C','D']:
        df[[col]].to_excel(writer,
                           sheet_name=col)

Read from that file

col_a = pd.read_excel(filepath,
                      sheet_name='A',
                      index_col=0)
col_a
A
0 0.554371
1 0.613897
2 0.275948
3 0.276886
4 0.157003
5 0.362938
6 0.659269
7 0.247132
8 0.791949
9 0.445282