pandas 的to_excel函数生成意外的TypeError [英] The function to_excel of pandas generate an unexpected TypeError

查看:260
本文介绍了 pandas 的to_excel函数生成意外的TypeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个熊猫数据框字典:

I created a dictionary of pandas dataframe:

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

所以我认为d[k]是正确的熊猫数据框.

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

然后

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

然后我出现错误:

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

我正在使用Python 3.7,pandas 0.25.3.

I am using Python 3.7, pandas 0.25.3.

更新:如果我将to_excel替换为to_csv,则代码可以正常运行.

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

推荐答案

我对openpyxl=3.0.2有相同的问题,

请参阅此 answer ,我将openpyxl回滚到3.0.1(conda或pip),并且可以正常工作.

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

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

这篇关于 pandas 的to_excel函数生成意外的TypeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆