AttributeError:模块“pandas”没有属性“read_xml”或“to_xml”

Posted

技术标签:

【中文标题】AttributeError:模块“pandas”没有属性“read_xml”或“to_xml”【英文标题】:AttributeError: module 'pandas' has no attribute 'read_xml' or 'to_xml' 【发布时间】:2021-09-10 22:50:00 【问题描述】:

我正在尝试将导出的 opml 文件解析成 xml 文件。

我通过使用 listparser、dicttoxml 和 pandas 成功地做到了这一点。我想尝试使用 pandas read_xml() 和 to_xml() 来了解与我自己将 opml 解析为 xml 相比它的性能。

import pandas as pd
my_opml = './feedly-e42affb2-52f5-4889-8901-992e3a3e35de-2021-06-28.opml'
df = pd.read_xml(my_opml)

这些将是我得到的错误。

Traceback(最近一次调用最后一次): 文件“”,第 1 行,在 getattr 中的文件“/home/pysolver33/anaconda3/envs/feedly/lib/python3.9/site-packages/pandas/core/generic.py”,第 5465 行 返回对象。getattribute(自我,姓名) AttributeError: 'DataFrame' 对象没有属性 'read_xml'

df.to_xml("feedlyRSS.xml")

Traceback(最近一次调用最后一次): 文件“”,第 1 行,在 getattr 中的文件“/home/pysolver33/anaconda3/envs/feedly/lib/python3.9/site-packages/pandas/init.py”,第 244 行 raise AttributeError(f"模块 'pandas' 没有属性 'name'") AttributeError:模块“pandas”没有属性“read_xml”

我的熊猫版本是 1.2.5。我检查了 pip 和 1.2.5 应该是最新版本。我不能玩 read_xml 或 to_xml 有什么特别的原因吗?

【问题讨论】:

read_xml 仅在尚未发布的 1.3 版中可用。 我明白了!谢谢你告诉我这件事。我正在阅读官方文件,并且很困惑为什么我不能使用它们。再次感谢您! 【参考方案1】:

pandas 更新到最新版本。

pip install --upgrade pandas --user

pd.read_xml('file.xml') 在 1.3.0 版本中可用。

【讨论】:

我的 pandas 是 v1.3.3 但仍然报错

以上是关于AttributeError:模块“pandas”没有属性“read_xml”或“to_xml”的主要内容,如果未能解决你的问题,请参考以下文章

AttributeError:模块“pandas”没有属性“read_xml”或“to_xml”

Python查看pandas版本报错:AttributeError: module ‘pandas‘ has no attribute ‘_version_‘

解决AttributeError:模块'pandas'没有使用command-prompt或pycharm属性'core'

AttributeError:模块“numpy”没有属性“版本”

AttributeError:模块“numpy”没有属性“__version__”

Seaborn 的异常 - Pandas:AttributeError:'DatetimeIndex' 对象没有属性'mean'