-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
to_excel leaves ExcelWriter Handle Open #9145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@scls19fr Thanks for the report! Do you see the correct behaviour if you do it without |
@scls19fr Some things:
Code I used to test: df = pd.DataFrame(np.random.randn(3,3), columns=list('abc'))
engine = 'openpyxl' # or 'xlsxwriter', 'xlwt'
# standard
df.to_excel("out_{}_1.xlsx".format(engine), engine=engine)
# writer with context
with pd.ExcelWriter("out_{}_2.xlsx".format(engine), engine=engine) as writer:
df.to_excel(writer)
# writer with close
writer = pd.ExcelWriter("out_{}_3.xlsx".format(engine), engine=engine)
df.to_excel(writer)
writer.close()
# writer without close
writer = pd.ExcelWriter("out_{}_4.xlsx".format(engine), engine=engine)
df.to_excel(writer) For |
Thanks for this tip.
|
I suppose this depends on the behaviour of the used engine (if that already writes the file or not before closing the sheet explicitely). The question is what the expected behaviour should be. If closing is needed, this should at least be documented better. |
Is this fixed by #30096? |
Guessing this was closed by #30096. Happy to reopen if this wasnt the case. |
Hello,
try
Only
out_xlsxwriter.xlsx
is createI was expecting
out_openpyxl.xlsx
andout_xlwt.xls
to be created.See also #9139
Kind regards
The text was updated successfully, but these errors were encountered: