Search code examples
pythonsentiment-analysis

AttributeError: 'Series' object has no attribute 'encode' in SentimentIntensityAnalyzer


I have scraped tweets using snscrape library in python. I was willing to get the sentiment for each of the tweets. In order to do That, I have used SentimentIntensityAnalyzer() from nltk and the following error popped up.

AttributeError: 'Series' object has no attribute 'encode'

I went back to the dataset resulted from the scraping and it shows the type of the Text column of the dataset as the following

type(data['Text'])
Out[42]: pandas.core.series.Series

I tried to change the data type and do other operations but the results were not positive. What approach should I take?

Thank you!


Solution

  • Passing data['Text'] through pandas.apply() function and then using SentimentIntensityAnalyzer() does the trick. The fact is the function is not capable of handling the series object. Passing one by one element to SentimentIntensityAnalyzer() using a looping function does the job in this case.