3.0.3 Export to Excel
Example:
##############################
# use 'to_excel()' and specify a file path and sheet name for your .xlsx file
DF.to_excel("/Path/to/your/data.xlsx"
, sheet_name = "my_sheet_name")
##############################
# Save multiple DFs to multiple sheets
# in this example we're exporting the same dataset to multiple sheets
with pd.ExcelWriter("/Path/to/your/data.xlsx") as writer:
DF.to_excel(writer, sheet_name='Sheet_name_1')
DF.to_excel(writer, sheet_name='Sheet_name_2')
###############################
# Append/Add new DF to a new sheet in an existing Excel file without overwriting the old file
with pd.ExcelWriter("/Path/to/your/data.xlsx"
, mode='a' # specify the 'append mode' with 'a'
, engine="openpyxl") as writer:
DF.to_excel(writer, sheet_name='Appended_Sheet')