I'm trying to insert a new dataframe column with only the 'positive' or 'negative' string according to TextBlob classification ex: for the 1st line of my df the result is (pos, 0.75, 0.2499999999999997) and I would like to have 'positive' in a new column named 'algo_sentiment', I've been trying with this code:
def sentiment_algo(text):
try:
if TextBlob (text, analyzer=NaiveBayesAnalyzer()).sentiment == neg:
return 'negative'
return 'positive'
except:
return None
df_test['algo_sentiment'] = df_test['cleaned_tweets'].apply(sentiment_algo)
The new colum is indeed created, but returns always either everything positive or everything negative. I've runned some tests and cannot find a solution.