Python: UnicodeDecodeError using pandas.read_excel

落花浮王杯 提交于 2019-12-11 18:31:38

问题


import pandas as pd

msf=pd.read_excel('‪C:\Users\pauldufosse\Documents\TESTDANIEL.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:\Users\pauldufosse\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3052, in run_code self.showtraceback()

File "C:\Users\pauldufosse\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 1851, in showtraceback value, tb, tb_offset=tb_offset)

File "C:\Users\pauldufosse\Anaconda\lib\site-packages\IPython\core\ultratb.py", line 1240, in structured_traceback self, etype, value, tb, tb_offset, number_of_lines_of_context)

File "C:\Users\pauldufosse\Anaconda\lib\site-packages\IPython\core\ultratb.py", line 1157, in structured_traceback self, etype, value, elist, tb_offset, number_of_lines_of_context

File "C:\Users\pauldufosse\Anaconda\lib\site-packages\IPython\core\ultratb.py", line 509, in structured_traceback out_list.extend(self._format_list(elist))

File "C:\Users\pauldufosse\Anaconda\lib\site-packages\IPython\core\ultratb.py", line 547, in _format_list item += ' %s\n' % line.strip()

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


回答1:


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.



来源:https://stackoverflow.com/questions/31558994/python-unicodedecodeerror-using-pandas-read-excel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!