我有一个包含100条推文的csv文件。我想处理这些推文中的每一个。所以,我写这段代码
import csv
with open('abctweets.csv',) as csvfile:
reader = csv.DictReader(csvfile)
count=0
for row in reader:
string = row['text']
count=count+1
print(count)
但在处理了578条推文后,它会抛出以下错误: -
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 6784: character maps to <undefined>
根据答案我修改了代码
import csv with open('J_tsar_tweets.csv', encoding="utf8") as csvfile:
reader = csv.DictReader(csvfile)
count=0
for row in reader:
string = row['text']
count=count+1
print(count)
但是它甚至不处理578条推文并抛出错误: (结果,消费)=
self._buffer_decode(data,self.errors,final)UnicodeDecodeError: &#39; UTF-8&#39;编解码器不能解码位置1193中的字节0xa0:无效启动 字节