I am trying to read an excel file in python without using pandas
or xlrd
, and I have been trying to convert the results from bytes
to utf-8
without any success.
data from xls file
colA colB colC
spc 1D0 20190705
spd 1D0 20190705
spe 1D0 20190705
... (goes on for 500k lines)
code
with open(file, 'rb') as f:
data = f.readlines(1) # Just to check the first line that is printed out
print(data[0].decode('utf-8'))
The error I receive is UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte
If I were to print data
without decoding it, the result is: [b'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00>\x00\x03\x00\xfe\xff\t\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x9e\x00\x00\x00\x9dN\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\xfe\xff\xff\xff\x00\x00\x00\x00\xfeM\x00\x00\x01\x00\x00\x00\xffM\x00\x00\x00N\x00\x00\x01N\x00\x00\x02N\x00\x00\x03N\x00\x00\x04N\x00\x00\x05N\x00\x00\x06N\x00\x00\x07N\x00\x00\x08N\x00\x00\tN\x00\x00\n']
There isn't any reason why I don't want to use pandas
or xlrd
, I am just trying to parse the data with just the standard libraries if required.
Any thoughts?