本文介绍了openpyxl模块-找不到openpyxl.utils.dataframe.dataframe_to_rows函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用Pandas和Excel,并且正在使用openpyxl模块.

I am currently working with Pandas and Excel and am using the openpyxl module.

我正在尝试编写一个Excel格式的DataFrame,openpyxl文档指出应该使用"openpyxl.utils.dataframe.dataframe_to_rows()"函数. ( http://openpyxl.readthedocs.io/en/default/pandas.html)

I am attempting to write a DataFrame to excel, and the openpyxl documentation states that one should use the "openpyxl.utils.dataframe.dataframe_to_rows()" function. (http://openpyxl.readthedocs.io/en/default/pandas.html)

但是,当我尝试使用它时,出现以下错误:

However when I try to use it I get the following error:

from openpyxl.utils.dataframe import dataframe_to_rows

for r in dataframe_to_rows(df, index=True, header=True):
    ws.append(r)

ImportError: No module named 'openpyxl.utils.dataframe'

我尝试过:

import openpyxl.utils

哪一个都没有问题.

当我跑步时:

dir(openpyxl.utils)

我没有提到数据框".

我做错什么了吗,或者openpyxl的文档过时了?

Am I doing something wrong, or is the documentation for openpyxl out of date?

任何人都对如何轻松地将数据帧传输到我使用openpyxl打开的excel工作簿中有任何想法吗?

Anyone have any ideas about how i can easily transfer a dataframe into an excel workbook that i have opened with openpyxl?

推荐答案

查理·克拉克(Charlie Clark)的正确答案-我有2.3.2版,并且我升级到了2.4.1版,此时导入可以正常进行.

Correct answer from Charlie Clark - I had version 2.3.2 and I upgraded to version 2.4.1 at which point the import worked.

这篇关于openpyxl模块-找不到openpyxl.utils.dataframe.dataframe_to_rows函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 11:48
查看更多