Python:使用pandas.read_excel的UnicodeDecodeError [英] Python: UnicodeDecodeError using pandas.read_excel

查看:279
本文介绍了Python:使用pandas.read_excel的UnicodeDecodeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import pandas as pd

msf=pd.read_excel('‪C:\Users\pauldufosse\Documents\TESTDANIEL.xlsx', has_index_names=True)

我在导入此xlsx文档时遇到困难.

I'm having difficulties importing this xlsx document.

我会给您完整的追溯信息,因为您可能会帮助我在哪里找到错误的字节. 我是法国人,所以有一个字符à",但我认为这个是由ascii/utf-8负责的,对吗?

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') 追溯(最近一次通话):

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

文件"C:\ Users \ pauldufosse \ Anaconda \ lib \ site-packages \ IPython \ core \ interactiveshell.py",第3052行,在run_code中 self.showtraceback()

File "C:\Users\pauldufosse\Anaconda\lib\site-packages\IPython\core\interactiveshell.py", line 3052, in run_code self.showtraceback()

文件"C:\ Users \ pauldufosse \ Anaconda \ lib \ site-packages \ IPython \ core \ interactiveshell.py",行1851,在showtraceback中 值,tb,tb_offset = tb_offset)

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

文件"C:\ Users \ pauldufosse \ Anaconda \ lib \ site-packages \ IPython \ core \ ultratb.py",行1240,结构化跟踪 自我,etype,值,tb,tb_offset,number_of_lines_of_context)

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)

文件"C:\ Users \ pauldufosse \ Anaconda \ lib \ site-packages \ IPython \ core \ ultratb.py",行1157,结构化跟踪 自我,类型,值,清单,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

文件"C:\ Users \ pauldufosse \ Anaconda \ lib \ site-packages \ IPython \ core \ ultratb.py",行509,结构化跟踪 out_list.extend(self._format_list(elist))

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

文件"C:\ Users \ pauldufosse \ Anaconda \ lib \ site-packages \ IPython \ core \ ultratb.py",第547行,在_format_list中 项目+ ='%s \ n'%line.strip()

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

UnicodeDecodeError:"ascii"编解码器无法解码位置19的字节0xe2:序数不在范围(128)中

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

推荐答案

ultratb中的unicode转换问题掩盖了ultratb试图显示的原始异常.

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

根据周围的示例,您通过传递例如,可以告诉pandas.read_excel使用哪种编码encoding="utf-8",就像使用 read_csv 一样.

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.

这篇关于Python:使用pandas.read_excel的UnicodeDecodeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆