Search code examples
python-3.xpandasxlscognos

Open with Pandas in Python a .xls file that is corrupted


So here is the problem, I'm trying to import a DF from a file downloaded from COGNOS. In cognos I select .CSV format but always is downloaded the format is .xls

It will be very easy to open the .xls file and save as CVS but the problem with that is that the file has more rows than excel so I will lose a lot of data in the process. Also when I open the file in excel it is a warning that the file could be corrupted.

When I'm trying to open the data with df = pd.read_excel("Time Series 2018-1.xls") it shows the following problem.

XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\xff\xfeP\x00r\x00o\x00'

Please HELP


Solution

  • I already resolve it. Just open the file in sublime and save with encoding UTF-8. Then just open it with df = pd.read_csv("Prueba1.xls", sep = "\t", encoding = 'utf8') because as @dougp said, is just a csv file save with the extension xls.

    I guess there is a way to change the encoding in PYTHON but that's for another question.