【问题标题】:Pandas ExcelWriter(...,engine='odf') - no module named odfPandas ExcelWriter(...,engine='odf') - 没有名为 odf 的模块
【发布时间】:2022-01-09 13:49:02
【问题描述】:

我很困惑为什么我无法将我的数据保存到 .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'

【问题讨论】:

    标签: python pandas ods


    【解决方案1】:

    正如@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")
    

    【讨论】:

      【解决方案2】:

      尝试安装 odfpy

      pip install odfpy
      

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

      【讨论】:

      • 感谢 Navyad。我很惊讶文档没有提到这个要求。谷歌也没有太大帮助。我永远不会知道这一点。
      猜你喜欢
      • 2022-01-16
      • 1970-01-01
      • 2020-12-26
      • 1970-01-01
      • 1970-01-01
      • 2014-05-28
      • 1970-01-01
      • 2014-03-02
      • 1970-01-01
      相关资源
      最近更新 更多