The function to_excel of pandas generate an unexpected TypeError

杀马特。学长 韩版系。学妹 提交于 2019-12-29 06:55:11

问题


I created a dictionary of pandas dataframe:

d[k] = pd.DataFrame(data=data[i])

So I assume that d[k] is a correct pandas dataframe.

Then

for k in d.keys():
  d[k].to_excel (file_name)

Then I have the error:

TypeError: got invalid input value of type <class 'xml.etree.ElementTree.Element'>, expected string or Element

I am using Python 3.7, pandas 0.25.3.

Update: if I replace to_excel by to_csv, the code runs perfectly.


回答1:


I have same problem with openpyxl=3.0.2,

Refer to this answer, I roll openpyxl back to 3.0.1(conda or pip) and it works.

>>> conda remove openpyxl
>>> conda install openpyxl==3.0.1

or

>>> pip uninstall openpyxl
>>> pip install openpyxl==3.0.1


来源:https://stackoverflow.com/questions/59168758/the-function-to-excel-of-pandas-generate-an-unexpected-typeerror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!