nltkを使用して感情を分析するプロジェクトで作業しています。私はGHを検索し、sentimaent_analyserやpopularity_scoresの呼び出しには何も似ていないことがわかりました。sentiment_analyserエラー: 'bytes'オブジェクトに 'エンコード'属性がありません。
私はまた、Python 3.4 - 'bytes' object has no attribute 'encode'を見ました。私はbcrypt.gensalt()。encode( 'utf-8')を呼んでいないので、重複していません。それは何かが間違ったタイプの問題を示唆していますが。
誰でもこのエラーを解決できますか?
私はエラーを取得:
/lib/python3.5/site-packages/nltk/sentiment/vader.py in init(self, text) 154 def init(self, text): 155 if not isinstance(text, str): --> 156 text = str(text.encode('utf-8')) 157 self.text = text 158 self.words_and_emoticons = self._words_and_emoticons()
AttributeError: 'bytes' object has no attribute 'encode'
データフレームdf_stocks.head(5)である:
prices articles
2007-01-01 12469 What Sticks from '06. Somalia Orders Islamist...
2007-01-02 12472 Heart Health: Vitamin Does Not Prevent Death ...
2007-01-03 12474 Google Answer to Filling Jobs Is an Algorithm...
2007-01-04 12480 Helping Make the Shift From Combat to Commerc...
2007-01-05 12398 Rise in Ethanol Raises Concerns About Corn as...
コードは、最後の行にoccuringエラーで以下の通りです:
import numpy as np
import pandas as pd
from nltk.classify import NaiveBayesClassifier
from nltk.corpus import subjectivity
from nltk.sentiment import SentimentAnalyzer
from nltk.sentiment.util import *from nltk.sentiment.vader import SentimentIntensityAnalyzer
import unicodedata
for date, row in df_stocks.T.iteritems():
sentence = unicodedata.normalize('NFKD', df_stocks.loc[date, 'articles']).encode('ascii','ignore')
ss = sid.polarity_scores(sentence)
を
ありがとうございました
可能な複製 - https://stackoverflow.com/questions/38246412/python-3-4-bytes-object-has-no-attribute-encode –
[Python 3.4 - 'bytes'オブジェクトの可能な複製は、属性がありません'encode'](https://stackoverflow.com/questions/38246412/python-3-4-bytes-object-has-no-attribute-encode) – eyllanesc
「df_stocks.loc [date、 'articles'] 'ユニコードstrではありません、df_stocksは何ですか? – aircraft