3

I'm new to Python and a have a problem. I'm trying to import an excel file with pandas and I'm using VS Code.

import pandas as pd

data = pd.read_excel(r'D:\Python\user.xlsx')
print(data)

I already installed xlrd, but however I get this error:

Traceback (most recent call last):
  File "d:\Python\import-excel.py", line 24, in <module>
    data = pd.read_excel(r'D:\Python\user.xlsx')
  File "D:\Python\venv\lib\site-packages\pandas\util\_decorators.py", line 296, in wrapper
    return func(*args, **kwargs)
  File "D:\Python\venv\lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel
    io = ExcelFile(io, engine=engine)
  File "D:\Python\venv\lib\site-packages\pandas\io\excel\_base.py", line 867, in __init__
    self._reader = self._engines[engine](self._io)
  File "D:\Python\venv\lib\site-packages\pandas\io\excel\_xlrd.py", line 22, in __init__
    super().__init__(filepath_or_buffer)
  File "D:\Python\venv\lib\site-packages\pandas\io\excel\_base.py", line 353, in __init__
    self.book = self.load_workbook(filepath_or_buffer)
  File "D:\Python\venv\lib\site-packages\pandas\io\excel\_xlrd.py", line 37, in load_workbook
    return open_workbook(filepath_or_buffer)
  File "D:\Python\venv\lib\site-packages\xlrd\__init__.py", line 170, in open_workbook
    raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
xlrd.biffh.XLRDError: Excel xlsx file; not supported

Can somebody help me?

funie200
  • 3,688
  • 5
  • 21
  • 34
Minecraft_Json
  • 207
  • 1
  • 4
  • 13
  • 1
    try changing the engine arg `pd.read_excel(r'D:\Python\user.xlsx',engine='openpyxl')` – Umar.H Dec 15 '20 at 10:39
  • 1
    thank you @Manakin but already done and got another error: **ValueError: Unknown engine: ** – Minecraft_Json Dec 15 '20 at 10:43
  • 2
    you might need to install `openpyxl` first `pip install openypyxl` see the dupe for others with that issue, seems to be quite a big breaking change – Umar.H Dec 15 '20 at 10:50
  • Ahhhh i saw it. i wrote engine=openpyxl instead of engine = 'openpyxl' :-))) also without **''**. Thanks – Minecraft_Json Dec 15 '20 at 10:55

1 Answers1

7

As noted by other members, xlrd has discontinued support for formats other than .xls.

Recommended is to use another library such as openpyxl.

As suggested by user Chris Withers in his answer:

  1. Install openpyxl: pip install openpyxl

  2. Implement your code as:

    import pandas as pd
    
    data = pd.read_excel(r'D:\Python\user.xlsx', engine='openpyxl')
    
    print(data)
    

Hope this works for you!

rama-a
  • 91
  • 7