UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb1 in position 871: invalid start byte
时间: 2023-09-27 12:08:11 浏览: 113
这个错误的原因是因为Python的read_csv函数默认使用utf-8编码读取文件,但是如果文件不是utf-8编码的话就会报错。解决这个问题的方法是更改读取文件的编码格式。常用的编码格式有ascii, gb18030, gbk, gb2312等。你可以尝试使用这些编码格式来读取文件,例如可以使用以下代码来读取编码格式为gb18030的文件:
stock = pd.read_csv(r'文件路径', encoding="gb18030") [2]
这样就可以成功读取文件并避免UnicodeDecodeError错误的出现。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [报错: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_2"}}] [.reference_item style="max-width: 50%"]
- *3* [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_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文