我在Python中使用csv模块,代码如下。当我使用一些简单的测试数据时,它工作正常,但当我切换到真实数据(包括一些非英文字符)时,我收到以下错误:
"UnicodeDecodeError: 'utf-8' codec can't decode byte 0x9c in position 1292: invalid start byte."
我知道问题是关于编码的问题,但我找不到任何能让我直接修复它的方法。帮助
import csv
import itertools
project_list = []
project_people = {}
with open('dbprojects.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row['project'] == '':
continue
elif row['project'] not in project_people:
person_list = [row['person']]
project_people.update({row['project']: person_list})
else:
project_people[row['project']].append(row['person'])