我很困惑为什么我不能把我的数据保存到一个.ods文档,并提供错误。我看了pandas.ExcelWriter()
的文档,它清楚地说明使用engine='odf'
能够保存为.ods
。
代码:
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")
错误:
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'
2条答案
按热度按时间d8tt03nd1#
尝试安装odfpy
https://pypi.org/project/odfpy/
zbdgwd5y2#
如@navyad建议
此外,请确保不要写入
engine='odfpy'
而不是engine='odf'