python报错:UnicodeDecodeError: ‘gbk‘ codec can‘t decode byte 0xaf in position 解决方案

原代码

data_path = "sources/weibo_senti_100k.csv"
data_list = open(data_path).readlines()[1:]

报错:

UnicodeDecodeError: ‘gbk’ codec can’t decode byte 0xaf in position 59

修改

data_path = "sources/weibo_senti_100k.csv"
data_list = open(data_path,"r",encoding='UTF-8').readlines()[1:]

打开文件时,进行加入编码格式

posted @ 2022-05-07 00:09  darling331  阅读(424)  评论(0编辑  收藏  举报