读取csv文件'utf-8' codec can't decode byte 0x87 in position 10: invalid start byte
时间: 2023-11-20 18:57:04 浏览: 340
读取CSV文件
读取csv文件时出现'utf-8' codec can't decode byte 0x87 in position 10: invalid start byte错误,这是因为文件中包含了非utf-8编码的字符。解决方法如下:
1.使用pandas库读取csv文件,并指定编码格式为'gbk'或'gb2312',例如:
```python
import pandas as pd
df = pd.read_csv('file.csv', encoding='gbk')
```
2.使用Python内置的csv库读取csv文件,并在打开文件时指定编码格式为'gbk'或'gb2312',例如:
```python
import csv
with open('file.csv', encoding='gbk') as f:
reader = csv.reader(f)
for row in reader:
print(row)
```
阅读全文