1

i would like to save a different dataframe in different excel pages withb a simpler loop. How can i construct correctly this loop?

my Currently codes are:

for fund in list(read_ex.keys()):
    writer = pd.ExcelWriter(excel_file, engine='xlsxwriter')
    data_2             .to_excel(writer, sheet_name= 'Df_ag')
    read_ex[fund]      .to_excel(writer, sheet_name= fund[:28])
    writer.save()

but the returns are only two page: the data_2 and the last in the loop. Thank you for your time!

Imopla

2
  • Just move the ExcelWriter(), the first to_excel() and save() outside the loop. Commented Aug 1, 2022 at 14:08
  • Can you reply using the "Answer" command ? Thks Commented Aug 1, 2022 at 14:12

1 Answer 1

1

For future readers:

I have been resolved this quastion in this way:

writer = pd.ExcelWriter(excel_file, engine='xlsxwriter')
data_2             .to_excel(writer, sheet_name= 'Df_ag')

for fund in list(read_ex.keys()):
    read_ex[fund]      .to_excel(writer, sheet_name= fund[:28]) 
 
writer.save()  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.