xxxxxxxxxx
# Save single dataframe to a single sheet
df.to_excel(excel_writer= 'file_name.xls',sheet_name='sheet_1',
startrow=1, startcol=1) # These are optional args
# Alternative approach : use context manager
# Save multiple dataframes in different sheets
df_list = [df1,df2,df3]
sheet_list = ['sheetA','sheetB','sheetC']
for df, sheet in zip(df_list,sheet_list):
with pd.ExcelWriter('file_name.xlsx') as writer:
df.to_excel(excel_writer=writer, sheet_name=sheet)
xxxxxxxxxx
df.to_excel(r'Path where you want to store the exported excel file\File Name.xlsx', index = False)
xxxxxxxxxx
#import openpyxl # Must be as least installed, import is optional
import pandas as pd
import numpy as np
# Create dataframe with your data;
df = pd.DataFrame(np.array([[23, 99, 78], [65, 95, 90], [90, 98, 96]]), columns=['Bob', 'Dilan', 'Live'])
df
Bob Dilan Live
0 23 99 78
1 65 95 90
2 90 98 96
# Export the dataframe as Excel File
# sheet_name="Your Sheet Name" is optionnal
df.to_excel(r'C:\Users\Ron\Desktop\File_Name.xlsx', sheet_name="Your Sheet Name" ,index = False)
xxxxxxxxxx
with pd.ExcelWriter('directory'+'Name of excel file') as writer:
Df.to_excel(writer, sheet_name='File_name')