When I run this code below, it returns 'float' object has no attribute 'encode'
Im not sure what Im doing wrong, but I want to get the VADER sentiment values for the Titles (which is in a large dataframe) but Im not sure where im going wrong, or how to convert the type of variable to make the object iterable. And then appending the 'compound' scores into the dataframe. I have tried iteration code like:
pd.concat([bitcoin,bitcoin['Title'].apply(lambda r : pd.Series(analyzer.polarity_scores(r)))],axis=1)
and
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)```
Without your data to work on, it is har to know. I saw you posted the same question elsewhere and some data so I tested it on:
and with a completion of your code (please, for further notice, do share which libraries you import):
which returns: