如何解决如何解决“浮动”对象没有“编码”属性
df_final['neg'] = df_final['Reviews'].apply(lambda x:sia.polarity_scores(x)['neg'])
df_final['neu'] = df_final['Reviews'].apply(lambda x:sia.polarity_scores(x)['neu'])
df_final['pos'] = df_final['Reviews'].apply(lambda x:sia.polarity_scores(x)['pos'])
df_final['compound'] = df_final['Reviews'].apply(lambda x:sia.polarity_scores(x)['compound'])
错误:
AttributeError Traceback (most recent call last)
<ipython-input-33-a5fdaf2a6c3e> in <module>
----> 1 df['neg'] = df['Reviews'].apply(lambda x:sid.polarity_scores(x)['neg'])
2 df['neu'] = df['Reviews'].apply(lambda x:sid.polarity_scores(x)['neu'])
3 df['pos'] = df['Reviews'].apply(lambda x:sid.polarity_scores(x)['pos'])
4 df['compound'] = df['Reviews'].apply(lambda x:sid.polarity_scores(x)['compound'])
~\anaconda3\lib\site-packages\pandas\core\series.py in apply(self,func,convert_dtype,args,**kwds)
4198 else:
4199 values = self.astype(object)._values
-> 4200 mapped = lib.map_infer(values,f,convert=convert_dtype)
4201
4202 if len(mapped) and isinstance(mapped[0],Series):
pandas\_libs\lib.pyx in pandas._libs.lib.map_infer()
<ipython-input-33-a5fdaf2a6c3e>
in<lambda>(x)
----> 1 df['neg'] = df['Reviews'].apply(lambda x:sid.polarity_scores(x)['neg'])
2 df['neu'] = df['Reviews'].apply(lambda x:sid.polarity_scores(x)['neu'])
3 df['pos'] = df['Reviews'].apply(lambda x:sid.polarity_scores(x)['pos'])
4 df['compound'] = df['Reviews'].apply(lambda x:sid.polarity_scores(x)['compound'])
~\anaconda3\lib\site-packages\nltk\sentiment\vader.py in polarity_scores(self,text)
358 """
359 # text,words_and_emoticons,is_cap_diff = self.preprocess(text)
--> 360 sentitext = SentiText(text,self.constants.PUNC_LIST,361 self.constants.REGEX_REMOVE_PUNCTUATION)
362 sentiments = []
~\anaconda3\lib\site-packages\nltk\sentiment\vader.py in __init__(self,text,punc_list,regex_remove_punctuation)
268 def __init__(self,regex_remove_punctuation):
269 if not isinstance(text,str):
--> 270 text = str(text.encode("utf-8"))
271 self.text = text
272 self.PUNC_LIST = punc_list
AttributeError: 'float' object has no attribute 'encode'
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。