0

I am trying to read data from excel to pandas. The file I get comes from api and is not saved (the access to the file needs special permissions, so I don't want to save it). When I try to read excel from file

with open('path_to_file') as file:
    re = pd.read_excel(file)

I get the error

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x98 in position
10: invalid start byte

When I input path in palce of file everythng works fine

re = pd.read_excel('path-to-exactly-the-same-file')

Is there a way to read excel by pandas without saving it and inputting path?

alis01
  • 169
  • 1
  • 3
  • 11

1 Answers1

1

the part that was missing was 'rb' in open

with open('path_to_file', 'rb') as file:
    re = pd.read_excel(file)

to treat the file as binary. Idea taken from error UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte

alis01
  • 169
  • 1
  • 3
  • 11