【问题标题】:UnicodeDecodeError: 'charmap' codec can't decode byte Z in position Y: character maps to <undefined>UnicodeDecodeError:“charmap”编解码器无法解码位置 Y 的字节 Z:字符映射到 <undefined>
【发布时间】:2017-12-18 17:05:17
【问题描述】:

我正在尝试使用大型训练数据集执行情绪分析。问题是,当我使用“sampleTweets.csv”进行分析时,一切都很好,只是分析不准确,因为 sampleTweets 数据集太小。

当我使用较大的数据集(例如“full_training_dataset.csv”)时,出现以下错误

返回 codecs.charmap_decode(input,self.errors,decoding_table)[0] UnicodeDecodeError:“charmap”编解码器无法解码位置 6961 中的字节 0x9d:字符映射到

我尝试添加 encoding="utf-8" 和其他编码,例如 latin-1,但是当我这样做时,程序会继续运行,而不会在控制台中产生任何结果。

以下是代码,这是项目的github链接:https://github.com/ravikiranj/twitter-sentiment-analyzer,我用的是simpleDemo.py文件。

#Read the tweets one by one and process it
inpTweets = csv.reader(open('data/full_training_dataset.csv', 'r'), delimiter=',', quotechar='|')
stopWords = getStopWordList('data/feature_list/stopwords.txt')
count = 0
featureList = []
tweets = []
for row in inpTweets:
    sentiment = row[0]
    tweet = row[1]
    processedTweet = processTweet(tweet)
    featureVector = getFeatureVector(processedTweet, stopWords)
    featureList.extend(featureVector)
    tweets.append((featureVector, sentiment))

【问题讨论】:

    标签: python csv character-encoding


    【解决方案1】:

    我知道这是一篇旧帖子,但这对我有用。

    1. 转到您的 python 安装:

      示例:C:\Python\Python37-32\Lib\site-packages\stopwordsiso

    2. 打开__init__.py

    3. 更改with open(STOPWORDS_FILE) as json_data:

      with open(STOPWORDS_FILE, encoding="utf8") as json_data:

    【讨论】:

      猜你喜欢
      • 2019-06-01
      • 2012-03-03
      • 2022-09-29
      • 2019-10-20
      • 2017-02-06
      • 2015-08-16
      • 2019-05-14
      相关资源
      最近更新 更多