Can't read_excel with pandas

2019-09-28 12:02发布

我学习大熊猫库。 在Python3,但我有一个很大的问题。 当我使用命令read_excel我得到一个错误。

import pandas as pd

df = pd.read_excel(r'D:\PythonProjects\stocks.xlsx',sheetname=0)

错误看起来是这样的:

C:\Users\Kuba\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\util\_decorators.py:118: FutureWarning: The `sheetname` keyword is deprecated, use `sheet_name` instead
  return func(*args, **kwargs)
Traceback (most recent call last):
  File "D:/MyPythonProjects/urlib.py", line 4, in <module>
    df = pd.read_excel(r'D:\MyPythonProjects\NewL\stocksa.xlsx',sheetname=0 )
  File "C:\Users\Kuba\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\util\_decorators.py", line 118, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\Kuba\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\excel.py", line 230, in read_excel
    io = ExcelFile(io, engine=engine)
  File "C:\Users\Kuba\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\io\excel.py", line 294, in __init__
    self.book = xlrd.open_workbook(self._io)
  File "C:\Users\Kuba\AppData\Local\Programs\Python\Python36\lib\site-packages\xlrd\__init__.py", line 141, in open_workbook
    ragged_rows=ragged_rows,
  File "C:\Users\Kuba\AppData\Local\Programs\Python\Python36\lib\site-packages\xlrd\xlsx.py", line 808, in open_workbook_2007_xml
    x12book.process_stream(zflo, 'Workbook')
  File "C:\Users\Kuba\AppData\Local\Programs\Python\Python36\lib\site-packages\xlrd\xlsx.py", line 265, in process_stream
    meth(self, elem)
  File "C:\Users\Kuba\AppData\Local\Programs\Python\Python36\lib\site-packages\xlrd\xlsx.py", line 392, in do_sheet
    sheet = Sheet(bk, position=None, name=name, number=sheetx)
  File "C:\Users\Kuba\AppData\Local\Programs\Python\Python36\lib\site-packages\xlrd\sheet.py", line 326, in __init__
    self.extract_formulas = book.extract_formulas
AttributeError: 'Book' object has no attribute 'extract_formulas'

我不知道如何解决它。 我已经试图重新安装大熊猫,xlrd和我仍然得到同样的错误。 你能给我一个建议如何修复这个问题。

Answer 1:

当你这样做会发生什么

pd.ExcelFile(filename)

如果抛出同样的错误,那么它可能因版本xlrd 。 我找不到extract_formulaxlrdBook ,从他们的最新版本的对象。 [资源]



Answer 2:

尝试安装

xlrd版本 '0.9.4'

工作对我来说



Answer 3:

只需添加在程序的开头:

import xlrd

在情况下,它没有找到,> PIP安装xlrd



文章来源: Can't read_excel with pandas