I have a dataframe that looks like this:
Text
0 this is amazing
1 nan
2 wow you are great
I want to iterate every word in a cell of the dataframe into textblob to get the polarity in a new column. However many rows have nan
in them.
I think this is causing TextBlob to implement scores of 0.0 for polarity in the new column for all rows even those with text in them.
How do I run TextBlob.sentiment.polarity over every text in my column and create a new column with the polarity scores?
New df should look like this:
Text sentiment
0 this is amazing 0.9
1 nan 0.0
2 wow you are great 0.8
I dont care about the nan
so the sentiment value can be nan
or 0.
Current code that is not working:
for text in df.columns:
a = TextBlob(text)
df['sentiment']=a.sentiment.polarity
print(df.value)
Thank you in advance.
edit:
To add, not sure if this makes a difference, the index on the df is not reset, for the fact that other parts of df are grouped together by the same index number.