Python读csv报'utf-8' codec can't decode byte 0xb3 in position 0: invalid start byte问题

'utf-8' codec can't decode byte 0xb3 in position 0: invalid start byte

Python读取csv文件时可能会遇到乱码或者报错:

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

只要把encoding= utf-8改成gbk即可
Python读csv报'utf-8' codec can't decode byte 0xb3 in position 0: invalid start byte问题
Python读csv报'utf-8' codec can't decode byte 0xb3 in position 0: invalid start byte问题

知其所以然,异常其实是读取的csv文件的编码导致的,通常有中文的csv文件中,excel会将其编译为ANSI的格式。我们可以通过用记事本打开查看到编码格式。同样的在记事本中另存为,可以修改编码格式为UTF-8,这样就能治标治本啦!
Python读csv报'utf-8' codec can't decode byte 0xb3 in position 0: invalid start byte问题
Python读csv报'utf-8' codec can't decode byte 0xb3 in position 0: invalid start byte问题

上一篇:Python读取文件时出现UnicodeDecodeError: 'gbk' codec can't decode byte 0x80 in position xx: 解


下一篇:达梦数据库类型查看