pandas read_excel返回PendingDeprecationWarning [英] Pandas read_excel returns PendingDeprecationWarning
问题描述
我一直在使用read_excel
函数将Excel文件作为Pandas数据框导入,到目前为止没有明显的问题.但是,我刚刚意识到,在最近进行一些更新后,我得到了以下警告:
I have been importing Excel files as Pandas data frames using the read_excel
function with no apparent issues so far. However, I just realized that after some recent updates I'm getting the below warning:
/usr/local/lib/python3.7/site-packages/xlrd/xlsx.py:266:PendingDeprecationWarning:在以后的版本中将删除此方法.改用"tree.iter()"或"list(tree.iter())".
/usr/local/lib/python3.7/site-packages/xlrd/xlsx.py:266: PendingDeprecationWarning: This method will be removed in future versions. Use 'tree.iter()' or 'list(tree.iter())' instead.
对于self.tree.iter()中的元素,如果Element_has_iter否则self.tree.getiterator(): /usr/local/lib/python3.7/site-packages/xlrd/xlsx.py:312:PendingDeprecationWarning:将来的版本中将删除此方法.改用"tree.iter()"或"list(tree.iter())".
for elem in self.tree.iter() if Element_has_iter else self.tree.getiterator(): /usr/local/lib/python3.7/site-packages/xlrd/xlsx.py:312: PendingDeprecationWarning: This method will be removed in future versions. Use 'tree.iter()' or 'list(tree.iter())' instead.
如果element_has_iter否则self.tree.getiterator()中的self.tree.iter()中的元素:
for elem in self.tree.iter() if Element_has_iter else self.tree.getiterator():
在Internet上搜索,看来xlrd
已被openpyxl
取代.现在我的问题是:
Searching the internet, it seems that the xlrd
is being replaced by openpyxl
. Now my questions are:
- 此警告是什么意思,我该怎么办?
- 此刻我的数据导入安全吗?我是否需要担心某些事情无法正常工作?
- 那些
tree.iter()
或list(tree.iter())
方法是什么?以及他们要替换什么? - 是否还有另一种方法可以将Excel文件作为熊猫数据框导入而又不会收到此警告?
- 我应该在某处报告错误或问题吗?在哪里?
- What does this warning mean and what should I do?
- Is my data import safe at this moment? Do I have to worry that something not working properly?
- What are those
tree.iter()
orlist(tree.iter())
methods? and what they are replacing? - Is there another method to import Excel files as pandas data frames without getting this warning already?
- Should I report a bug or issues somewhere? Where?
我的环境是:
- macOS Mojave 10.14.6
- Python 3.7.6
- 熊猫1.0.0
- xlrd 1.2.0
推荐答案
目前,您的数据导入是安全的".要摆脱警告和过时的代码,请尝试:
Your data import is "safe" at the moment. To get rid of the warning and future-proof your code, try:
pd.read_excel(filename, engine="openpyxl")
或将其放在脚本的开头:
or put this at the start of your script:
import pandas as pd
pd.set_option("xlsx", "openpyxl")
这篇关于 pandas read_excel返回PendingDeprecationWarning的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!