在 Python/PyCharm 中导出 Excel

问题描述 投票:0回答:1

我有一个 pandas 数据框,我想将其导出到 Excel,当我运行以下代码时;

AmortizingFloatingCashflows = pd.DataFrame(AmortizingFloatingCashflows)
AmortizingFloatingCashflows.to_excel('AmortizingFloatingCashflows.xlsx')

我收到以下错误;

Traceback (most recent call last):
  File "/Users/../Amortizing Swap/Amortizing swap.py", line 116, in <module>
    AmortizingFloatingCashflows.to_excel('AmortizingFloatingCashflows.xlsx')
  File "/Users/../venv/lib/python3.9/site-packages/pandas/core/generic.py", line 2252, in to_excel
    formatter.write(
  File "/Users/../venv/lib/python3.9/site-packages/pandas/io/formats/excel.py", line 934, in write
    writer = ExcelWriter(  # type: ignore[abstract]
  File "/Users/../venv/lib/python3.9/site-packages/pandas/io/excel/_openpyxl.py", line 56, in __init__
    from openpyxl.workbook import Workbook
ModuleNotFoundError: No module named 'openpyxl'

我已经安装了 openpyxl 但我仍然没有得到正确的结果。如何最好地将 pandas 数据框导出到 Excel 中?

python pycharm
1个回答
0
投票

错误消息表明您的Python环境中未安装

openpyxl
模块。
openpyxl
是Pandas操作Excel文件所需的第三方库。

您可以通过在终端或命令提示符中运行以下命令来安装“openpyxl”:

pip install openpyxl

安装完成后

openpyxl
,您应该能够运行代码而不会出现任何错误。

© www.soinside.com 2019 - 2024. All rights reserved.