4

I need to read a few xls files into Python.The sample data file can be found through Link:data.file. I tried:

import pandas as pd
pd.read_excel('data.xls',sheet=1)

But it gives an error message:

ERROR *** codepage 21010 -> encoding 'unknown_codepage_21010' -> LookupError: unknown encoding: unknown_codepage_21010 Traceback (most recent call last):

File "", line 1, in pd.read_excel('data.xls',sheet=1)

File "C:\Anaconda3\lib\site-packages\pandas\io\excel.py", line 113, in read_excel return ExcelFile(io, engine=engine).parse(sheetname=sheetname, **kwds)

File "C:\Anaconda3\lib\site-packages\pandas\io\excel.py", line 150, in init self.book = xlrd.open_workbook(io)

File "C:\Anaconda3\lib\site-packages\xlrd__init__.py", line 435, in open_workbook ragged_rows=ragged_rows,

File "C:\Anaconda3\lib\site-packages\xlrd\book.py", line 116, in open_workbook_xls bk.parse_globals()

File "C:\Anaconda3\lib\site-packages\xlrd\book.py", line 1170, in parse_globals self.handle_codepage(data)

File "C:\Anaconda3\lib\site-packages\xlrd\book.py", line 794, in handle_codepage self.derive_encoding()

File "C:\Anaconda3\lib\site-packages\xlrd\book.py", line 775, in derive_encoding _unused = unicode(b'trial', self.encoding)

File "C:\Anaconda3\lib\site-packages\xlrd\timemachine.py", line 30, in unicode = lambda b, enc: b.decode(enc)

LookupError: unknown encoding: unknown_codepage_21010

Anyone could help with this problem?

PS: I know if I open the file in windows excel, and resave it, the code could work, but I am looking for a solution without manual adjustment.

1
  • Its not only pandasc issue. others have same problem Commented Mar 26, 2015 at 3:18

2 Answers 2

2

using the ExcelFile class, I was successfully able to read the file into python. let me know if this helps!

    import xlrd
    import pandas as pd

    xls = pd.ExcelFile(’C:\data.xls’)
    xls.parse(’Index Constituents Data’, index_col=None, na_values=[’NA’])
Sign up to request clarification or add additional context in comments.

1 Comment

Looks like you haven't used xlrd in the code here however you imported it.
2

The below worked for me.

import xlrd


my_xls = xlrd.open_workbook('//myshareddrive/something/test.xls',encoding_override="gb2312")

1 Comment

Do you know how to convert my_xls into DataFrame?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.