Can't read_excel with pandas

独自空忆成欢 提交于 2019-12-24 01:58:54

问题


I am learning pandas lib. in Python3, but i have a big problem. When i use command to read_excel i get an error.

import pandas as pd

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

The error looks like this:

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'

I don't know how to fix it. I 've tried to reinstall pandas, xlrd and still i get the same error. Can you give me an advice how to repair that problem.


回答1:


What happens when you do

pd.ExcelFile(filename)

If that throws the same error, then it might due to the version of xlrd. I couldn't find extract_formula from xlrd's Book object from their latest release. [source]




回答2:


try installing the

xlrd version '0.9.4'

Worked for me




回答3:


just add at the beginning of your program:

import xlrd

in case it's not found, > pip install xlrd



来源:https://stackoverflow.com/questions/49325837/cant-read-excel-with-pandas

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