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?

1
  • 1
    Try to read the file as bytes: with open('path_to_file', 'rb') as file Commented Oct 7, 2020 at 11:47

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.