0

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


4

1 に答える 1

0

作業するデータがなければ、知ることは困難です。同じ質問を他の場所に投稿し、いくつかのデータを投稿したのを見たので、テストしました:

 index                                               text
0      0  I can’t believe Bitcoin is going to hit 100k b...
1      1  What new Bitcoin related project are you the m...
2      2  Yin decline is about to end! Historical data s...
3      3  If you discovered a way to model turning $100 ...
4      4  Happy New Year and some nice Gains !! ...

コードが完成したら (詳細については、インポートしたライブラリを共有してください):

from nltk import *
import pandas as pd
import vader
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()

bitcoin = df

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)
                
                
score_compound  

戻り値:

[0.0258, 0.4005, 0.0, 0.6199, 0.9421]
于 2022-01-24T12:46:29.880 に答える