我已经从Kaggle-https://www.kaggle.com/ngyptr/python-nltk-sentiment-analysis中导出了CSV。但是,当我尝试遍历文件时,收到与某些无法编码的字符有关的unicode错误。
File "C:\Program Files\Python35\lib\encodings\cp850.py",line 19,in encode
return codecs.charmap_encode(input,self.errors,encoding_map)[0]
UnicodeEncodeError:'charmap'编解码器无法对位置264中的字符'\ u2026'进行编码:字符映射至
我在打开文件时启用了utf-8编码,我认为该文件会解码ASCII字符。显然不是。
我的代码:
with open("sentimentdataset.csv","r",encoding="utf-8",errors='ignore',newline='') as file:
reader = csv.reader(file)-
for row in reader:
if row:
print(row)
if row[sentimentCsvColumn] == sentimentScores(row[textCsvColumn]):
accuracyCount += 1
print(accuracyCount)