Pandas: UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 0-1 中的字节:无效的连续字节 [英] Pandas: UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: invalid continuation byte

查看:88
本文介绍了Pandas: UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 0-1 中的字节:无效的连续字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

社区.我想使用 Pandas 打开一个 CSV 并对其进行分析.请帮忙,因为我无法打开 CSV 本身.我尝试使用 UTF-8、Latin-1 和 ISO-8859-1 编码打开它.它没有用.代码:

community. I want to open a CSV using pandas and perform analysis on it. Please, help as I am not able to open the CSV itself. I tried opening it with UTF-8, Latin-1, and ISO-8859-1 encoding. It didn't work. CODE:

csv_file3='COVID-19-geographic-disbtribution-worldwide.csv'
with open(csv_file3,'rt')as f:
    data = csv.reader(f)
    j=0
    for row in data:
         j+=1

错误:

Traceback (most recent call last):
  File "analysisofcases.py", line 87, in <module>
    for row in data:
  File "/usr/lib/python3.6/codecs.py", line 321, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 15-16: invalid continuation byte

这是我要打开的CSV.这是我的代码和运行代码时的错误.**请检查并查看问题所在是**

推荐答案

试试这个,检查这个 标准编码.

Try this,check this standard encodings as well.

data = pd.read_csv("COVID-19-geographic-disbtribution-worldwide.csv", encoding = 'unicode_escape', engine ='python')

这篇关于Pandas: UnicodeDecodeError: 'utf-8' 编解码器无法解码位置 0-1 中的字节:无效的连续字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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