-5

code:

import pandas as pd
import os
dirname = 'D:\SYun\BigData\DataScience-master\DataScience-master\data'
filename = '05. draw_korea_raw.xlsx'
path = os.path.join(dirname, filename)
f = pd.read_excel(path)
print(f)

error:

raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported')
xlrd.biffh.XLRDError: Excel xlsx file; not supported

i downloaded pandas==1.1.5, xlrd==2.0.1, openpyxl==3.0.5, jupyter==1.0.0, python==3.8 and trying to collect excel data to make a graph but the code can't read xlsx file. xls old excel version is fine but can't read new version of excel file. anyone knows how to solve this problem? or should i just use only xls data or convert to read the file.ㅠ.ㅠ

zoai
  • 1
  • 1
  • 1
  • 2
  • Please edit your question to be formatted properly. The title should be a title. Code should be code. Text should be text. Etc. – noah Dec 24 '20 at 00:50
  • 1
    But your problem is likely that xlrd doesn't work with xlsx files and openpyxl must be used instead – noah Dec 24 '20 at 00:50
  • are you sure that the xlsx exists in `D:\SYun\BigData\DataScience-master\DataScience-master\data\05. draw_korea_raw.xls`? – Shar Dec 24 '20 at 00:52
  • What's unclear about `FileNotFoundError: [Errno 2] No such file or directory`? – Julien Dec 24 '20 at 00:56
  • sorry i wrote wrong error i edited it. it saying xlsx not supported, but when i googled other people works, but mine is not working. just want to know anyone has same problem like me and fix – zoai Dec 24 '20 at 01:01
  • The error message seems rather self-explanatory, can you be more specific as to what the issue is? – AMC Dec 24 '20 at 01:39
  • @AMC i want to read excel2016 file using pandas package. but it alarming --> 170 raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported') 171 172 bk = open_workbook_xls( XLRDError: Excel xlsx file; not supported – zoai Dec 24 '20 at 02:20
  • @zoai Yes, I saw that in the post. – AMC Dec 24 '20 at 02:24

2 Answers2

2

The latest version of xlrd(2.01) only supports .xls files. Installing the older version 1.2.0 may work to open .xlsx files.

Or to solve this, do the following:

  1. Install openpyxl: This is another excel package that still supports the xlsx format

  2. Set the engine to “openpyxl” instead of the default “xlrd”

    # Install openyxl
    pip install openpyxl
    # set engine parameter to "openpyxl"
    pd.read_excel(path, engine = 'openpyxl')
    
Shaiful Islam
  • 359
  • 2
  • 13
  • 1
    thank you #Islam. i tried as you said 1. putting r before the path and 2. simplified the path but still i get the problem "xlsx is not supported" so i decide to use openpyxl to open the file and view it with pandas DataFrame. thank you for your help – zoai Dec 24 '20 at 01:51
0

tried many times to read xlsx file with pandas and xlrd. but i couldn't get the solution that i want. so i made a conclusion. the bast way is converting xlsx to xls 'OR' using openpyxl

import openpyxl
import pandas as pd

wb = openpyxl.load_workbook('./06. result.xlsx')
sheet = wb.worksheets[0]

f = pd.DataFrame(sheet.values)

but this code makes NaN on the first column.

zoai
  • 1
  • 1
  • 1
  • 2