'utf-8' codec can't decode byte 0xb7 in position 2: invalid start byte
时间: 2023-10-13 20:05:08 浏览: 115
这个错误是由于'utf-8'编码无法解码位于特定位置的字节0xb7导致的。解决方法有几种:
1. 你可以尝试继续读取文件,但是可能会出现乱码。可以使用以下代码来指定使用ISO-8859-1编码来读取文件:pd.read_csv('pathfile', encoding='ISO-8859-1')。
2. 可以尝试改用gbk编码来读取文件,可以使用以下代码进行改进:open函数的解释。
3. 如果遇到某些文件仍然报错,错误信息为"UnicodeDecodeError: 'gbk' codec can't decode byte 0x81 in position 414: illegal multibyte sequence",可以将encoding方式改为GB18030来解决问题:df = pd.read_csv(file_path + '/' + filename[i], encoding='GB18030')。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb7 in position 0: invalid start byte——已...](https://blog.csdn.net/weixin_44343458/article/details/131947201)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [python机器学习mooc解决K-means代码无法运行的问题](https://download.csdn.net/download/weixin_38551376/13743426)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb7 in position 2: invalid](https://blog.csdn.net/weixin_52166332/article/details/120770785)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文