我搞不懂为什么我无法将数据保存到.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'
发布于 2021-12-03 06:07:51
发布于 2021-12-03 06:46:26
如@navyad所建议
!pip install odfpy
另外,请确保您的没有写engine='odfpy'
,而不是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")
https://stackoverflow.com/questions/70210144
复制相似问题