pd.read_csv:utf-8'编解码器无法解码位置61的字节0x98:无效的起始字节 [英] pd.read_csv: utf-8' codec can't decode byte 0x98 in position 61: invalid start byte

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

问题描述

我想从以下位置下载csv文件:

请尝试2015财年.

我的代码如下:

  a = pd.read_csv('C://.../fy15_federal-state_summaries.csv',encoding ="utf-8") 

但是我仍然遇到错误:

  UnicodeDecodeError:'utf-8'编解码器无法解码位置61的字节0x98:无效的起始字节 

我也尝试了不同的方法.但是,一切都不起作用.有人可以在这里帮助我吗?

解决方案

这是 encoding 问题.

您需要找出文件的正确编码.

在这种情况下,它是 1250 ,所以:

  a = pd.read_csv(r'C:\ ... \ fy15_federal-state_summaries.csv',encoding ="1250") 

I want to download a csv file from: https://www.osha.gov/fatalities/reports/archive.

Please try the FY15 one.

My code is like:

a=pd.read_csv('C://.../fy15_federal-state_summaries.csv',encoding = "utf-8")

But I still have got the error:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0x98 in position 61: invalid start byte

I have also tried different ways. But all do not work. Could anyone help me here?

解决方案

It is encoding issue.

You need to find out the correct encoding of the file.

In this case it is 1250, so:

a=pd.read_csv(r'C:\...\fy15_federal-state_summaries.csv',encoding = "1250")

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

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