Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
395 views
in Technique[技术] by (71.8m points)

Python: UnicodeDecodeError using pandas.read_excel

import pandas as pd

msf=pd.read_excel('?C:UserspauldufosseDocumentsTESTDANIEL.xlsx', has_index_names=True)

I'm having difficulties importing this xlsx document.

I will give you the full traceback as you might help me to find WHERE the wrong byte is. I'm french so there is the character 'à' but I think this one is taken in charge by ascii/utf-8 am i right?

runfile('C:/Users/pauldufosse/Documents/MSF.py', wdir='C:/Users/pauldufosse/Documents') Traceback (most recent call last):

File "C:UserspauldufosseAnacondalibsite-packagesIPythoncoreinteractiveshell.py", line 3052, in run_code self.showtraceback()

File "C:UserspauldufosseAnacondalibsite-packagesIPythoncoreinteractiveshell.py", line 1851, in showtraceback value, tb, tb_offset=tb_offset)

File "C:UserspauldufosseAnacondalibsite-packagesIPythoncoreultratb.py", line 1240, in structured_traceback self, etype, value, tb, tb_offset, number_of_lines_of_context)

File "C:UserspauldufosseAnacondalibsite-packagesIPythoncoreultratb.py", line 1157, in structured_traceback self, etype, value, elist, tb_offset, number_of_lines_of_context

File "C:UserspauldufosseAnacondalibsite-packagesIPythoncoreultratb.py", line 509, in structured_traceback out_list.extend(self._format_list(elist))

File "C:UserspauldufosseAnacondalibsite-packagesIPythoncoreultratb.py", line 547, in _format_list item += ' %s ' % line.strip()

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 19: ordinal not in range(128)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

That unicode conversion problem in ultratb is obscuring whatever the original exception was that ultratb is trying to display.

Judging by the examples around, you can tell pandas.read_excel what encoding to use by passing e.g. encoding="utf-8" as you would with read_csv.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...