UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf9 in position 98: invalid start byte
时间: 2023-10-22 16:30:27 浏览: 144
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf9 in position 98: invalid start byte是一个错误信息,表明在解码时无法将字节0xf9解码为有效的UTF-8字符。
这个错误通常出现在使用pd.read_csv函数读取文件时,默认情况下,该函数使用UTF-8编码进行解码。如果文件的编码格式不是UTF-8,就会报错。
解决这个问题的方法是更改读取文件的编码格式。常用的编码格式有ascii, gb18030, gbk, gb2312。你可以尝试使用不同的编码格式来读取文件,直到找到正确的编码格式为止。例如,可以使用以下代码更改编码格式为gb18030来读取文件:stock = pd.read_csv(r'文件路径', encoding="gb18030")。
另外,如果这个错误是在网页访问中出现的,可能是因为浏览器会自动解压缩从服务器返回的压缩网页,而我们编写的代码没有进行自动解码处理,导致乱码。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
#### 引用[.reference_title]
- *1* [UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd5 in position 2: invalid continuation byte-...](https://download.csdn.net/download/weixin_42204453/15589184)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* *3* [报错:UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb0 in position 2: invalid start byte](https://blog.csdn.net/m0_56230003/article/details/130326974)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *4* [UnicodeDecodeError: utf-8 codec can t decode byte 0x8b in position 1: invalid start byte](https://blog.csdn.net/m0_52613986/article/details/129739448)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文