To get data from function you would have to keep all strings on list - without print()
and use return
to return it
def sentiment_analyzer_scores(data):
results = []
for sentence in data:
score = analyser.polarity_scores(sentence)
text = "{<40{}".format(sentence, str(score))
results.append(text)
return results
df['results'] = sentiment_analyzer_scores(df['clean_text'])
or in new DataFrame
results = sentiment_analyzer_scores(df['clean_text'])
new_df = pd.DataFrame(results)
But maybe you should use .apply()
instread of for
-loop
More or less
def sentiment_analyzer_scores(sentence):
score = analyser.polarity_scores(sentence)
returm "{<40{}".format(sentence, str(score))
df['results'] = df['clean_text'].apply(sentiment_analyzer_scores)
or in new DataFrame
results = df['clean_text'].apply(sentiment_analyzer_scores)
new_df = pd.DataFrame(results)