from textblob import TextBlob
def sentiment_calc(text):
try:
return TextBlob(text).sentiment
except:
return None
test_df['sentiment score'] = test_df['text'].apply(sentiment_calc)
test_df
I recently ran a code on my dataset to implement sentiment analysis using the TextBlob package. After running that, my sentiment column has the following output below (I did an example table with dummy numbers below).
text | sentiment score
------------------------
nice | (0.45, 4.33)
good | (0.45, 4.33)
ok | (0.45, 4.33)
And the output I would like to get is this, where I split the sentiment column into two columns, but add those columns onto the current dataframe.
text | polarity | subjectivity
------------------------------
nice |0.45 | 0.433
good |0.45 | 0.433
ok |0.45 | 0.433
Is there a way to do this in Python 2.7?