热线电话:13121318867

登录
2020-12-28 阅读量: 1107
python报错: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 0

问:

python报错:

UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd6 in position 0

image.png


答:

出现此报错一般是文件编码问题,可通过以下方法查看编码后通过指定编码读取数据即可。

pd.read_csv("movie.csv") # unicodedecodeerror 编码错误
import chardet # 判断编码
f = open("movie.csv","rb") # r read b 二进制
data = f.read() # 读取刚刚二进制打开文件的数据
chardet.detect(data) # detect 判断data的编码
pd.read_csv("movie.csv",encoding="gbk") # 带上编码读取数据
f.close()


59.9825
0
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子