Creating an excel output with multiple sheet
I am trying to create and excel output with multiple sheet. This is what i've come up with so far.
with output.get_writer("Summary_File"+current_day+".xlsx") as writer:
report_df.to_excel(writer, sheet_name='summary')
cleaned_inbound_prepared_distinct_prepared_joined_df.to_excel(writer, sheet_name='Duplicates')
distinct_biomakers_df.to_excel(writer, sheet_name='Biomakers')
distinct_subjid_df.to_excel(writer, sheet_name='SubjectIDS')
distinct_visits_df.to_excel(writer, sheet_name='Vists')
all_df.to_excel(writer, sheet_name='numeric')
less_than_df.to_excel(writer, sheet_name='non_numeric')
Operating system used: windows
Best Answer
-
Ashley Dataiker, Alpha Tester, Dataiku DSS Core Designer, Registered, Product Ideas Manager Posts: 162 Dataiker
Hi @Scobbyy2k3
,You might want to try the the Multisheet Excel export plugin which lets you take several different datasets and export them onto different tabs of a single Excel file.
Cheers,
Ashley W.
Answers
-
sheet_names = ['1', '2']# First, save the data as excel format into a bytes stringstream = BytesIO()excel_writer = pd.ExcelWriter(r"C:\Users\XXXX\Downloads\pythonCode\Multiple_Merged.xlsx", engine='xlsxwriter')for i, df inenumerate (dataframes):df.to_excel(excel_writer, sheet_name=sheet_names[i],index=False)workbook = excel_writer.bookworksheet = excel_writer.sheets[sheet_names[i]]
more formatting
excel_writer.save()# Rewind to the beginning of the bytes stringstream.seek(0)