当我在下面运行此代码时,它返回'float' object has no attribute 'encode'
我不确定我做错了什么,但我想获取标题的 VADER 情绪值(在一个大数据框中)但我不确定我哪里出错了,或者如何转换使对象可迭代的变量类型。然后将“复合”分数附加到数据框中。我尝试过迭代代码,例如:
pd.concat([bitcoin,bitcoin['Title'].apply(lambda r : pd.Series(analyzer.polarity_scores(r)))],axis=1)
和
score_compound = bitcoin['Title'].apply(lambda r : analyzer.polarity_scores(r)['compound'])
import nltk
import pandas as pd
analyzer = SentimentIntensityAnalyzer()
bitcoin = pd.read_csv("Subreddit_Bitcoin_2021.csv")
score_compound = []
for i in range(0, bitcoin.shape[0]):
score = analyzer.polarity_scores(bitcoin.iloc[i][1])
score1 = score['compound']
score_compound.append(score1)```