sentiment_analyser error: 'bytes' object has no attribute 'encode' using
使用NLTK进行感情分析项目。我通过GH搜寻并没有发现任何相似之处
我也在看Python3.4---字节对象没有特性编码,也不是复制品,因为我不叫bcrypt.gensalt().尽管这是个错误的问题。
有人能帮助解决这个错误吗?
我找错人了
/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'
The dataframe DF&U stocks.head(5)is:
1 2 3 4 5 6 | 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... |
The code is below with the error occuring on the last line:
ZZU1
谢谢
从unicodedata.normalize(文件)的方法,convert A Unicode字符串的冰到普通格式的字符串。
1 2 3 | import unicodedata print(unicodedata.normalize('NFKD', u'abcdあ?asc').encode('ascii', 'ignore')) |
它将得到:
1 | b'abcdaasc' |
所以,问题是这里: