以下のこのコードを実行すると、'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)```