maertsoi
maertsoi

Reputation: 117

Pandas ExcelWriter(...,engine='odf') - no module named odf

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'

Upvotes: 2

Views: 1978

Answers (2)

Talha Tayyab
Talha Tayyab

Reputation: 27725

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")

Upvotes: 1

navyad
navyad

Reputation: 3860

Try installing odfpy

pip install odfpy

https://pypi.org/project/odfpy/

Upvotes: 2

Related Questions