Pandas read_excel returns PendingDeprecationWarning

醉酒当歌 提交于 2020-05-14 12:08:25

问题


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: This method will be removed in future versions. Use 'tree.iter()' or 'list(tree.iter())' instead.

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.

for elem in self.tree.iter() if Element_has_iter else self.tree.getiterator():

Searching the internet, it seems that the xlrd is being replaced by openpyxl. Now my questions are:

  • 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() or list(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?

my environment is:

  • macOS Mojave 10.14.6
  • Python 3.7.6
  • Pandas 1.0.0
  • xlrd 1.2.0

回答1:


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")


来源:https://stackoverflow.com/questions/60288732/pandas-read-excel-returns-pendingdeprecationwarning

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