I'm analyzing the full text of a book using Textblob, aggregating the mood of the chapter by analyzing the sentences individually. I have a script which converts the chapters into lists of individual sentences, but I can't figure out a way to pass these list objects as strings to the Naive Bayes Analyzer since it only expects string inputs.
So far I've tried only passing the entire list as the argument, but it has always given me the same error.
TypeError: The `text` argument passed to `__init__(text)` must be a string,
not <class 'list'>
This is the code I have:
from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer
blob = TextBlob("This is a horrible idea.", analyzer=NaiveBayesAnalyzer())
blob.sentiment
print(blob.sentiment)
My list looks something like this:
sentences = ['Maria was five years old the first time she heard the word
hello.\n', 'It happened on a Thursday.\n',]
How do I alter this code to take in the entire list of sentences and pass the output as a dataframe? If possible, I would like something like this:
Line Polarity Subjectivity Classification
0 Mariam was five years old the first time sh 0.175000 0.266667 Pos
1 It happened on a Thursday. 0.000000 0.000000 Neu