我正在尝试将字典保存在csv文件中。所以我在python 3.7中写了以下代码
import csv
import os
with open('data_key_value.csv', 'w') as f:
w = csv.DictWriter(f, final_dict.keys())
w.writeheader()
w.writerow(final_dict)
但是我收到错误消息
UnicodeEncodeError: 'charmap' codec can't encode character '\u0170' in position 1843: character maps to <undefined>
我的文件中有一些特殊字符。我用过
pd.read_csv(r'C:\data.csv', encoding='utf-8-sig')
你能建议我如何保存字典