您的位置 首页 php

pandas无法读取CSV'utf-8' codec can't decode byte 0xb4 in position 0

问题:

‘utf-8’ codec can’t decode byte 0xb4 in position 0: invalid start byte

解决方案:

方法一:将 CSV 文件ANSI格式转化为UTF-8

方法二:Python( encoding设置编码格式 )

#读取CSV

tmp_arr = []

with open(‘test2.csv’, encoding=’utf-8 ‘)as f:

f_csv = csv.reader(f)

for row in f_ csv :

tmp_arr.append(row)

print(row)

header=[‘姓名’,2,3,4,5]

# 转换编码ANSI、UTF-8

with open(‘tmp_arr1.csv’,’w’,newline=”, encoding=’UTF-8-SIG ‘)as f:

#newline=” “是为了避免写入之后有空行 默认是UTF-8编码

ff=csv.writer(f)

ff.writerow(header)

ff.writerow(header)

ff.writerow(header)

ff.writerows(tmp_arr)

文章来源:智云一二三科技

文章标题:pandas无法读取CSV'utf-8' codec can't decode byte 0xb4 in position 0

文章地址:https://www.zhihuclub.com/80428.shtml

关于作者: 智云科技

热门文章

网站地图