I'm confused as to why I'm unable to save my data to a .ods document, with the provided error. I've looked at the documentation for pandas.ExcelWriter()
and it clearly states to use engine='odf'
to be able to save as a .ods
.
Code:
import pandas as pd
... # nothing of value
df = pd.DataFrame(data, columns=COLS, index=None)
with pd.ExcelWriter('new.ods', engine="odf") as doc:
df.to_excel(doc, sheet_name="Sheet1")
Error:
File "..../main.py", line 190, in <module>
with pd.ExcelWriter('new.ods', engine="odf") as doc:
File "..../Python38-32\lib\site-packages\pandas\io\excel\_odswriter.py", line 34, in __init__
from odf.opendocument import OpenDocumentSpreadsheet
ModuleNotFoundError: No module named 'odf'
CodePudding user response:
Try installing odfpy
pip install odfpy
https://pypi.org/project/odfpy/
CodePudding user response:
As suggested by @navyad
!pip install odfpy
Also, make sure you do not write engine='odfpy'
instead of engine='odf'
import pandas as pd
df = pd.DataFrame(data, columns=COLS, index=None)
with pd.ExcelWriter('new.ods', engine="odf") as doc:
df.to_excel(doc, sheet_name="Sheet1")