我正在使用Textblob分析一本书的全文,通过单独分析句子来汇总本章的内容。我有一个脚本,可以将各章转换成单个句子的列表,但是我无法找出一种将这些列表对象作为字符串传递给Naive Bayes Analyzer的方法,因为它只希望输入字符串。
到目前为止,我仅尝试将整个列表作为参数传递,但是它始终给我相同的错误。
TypeError: The `text` argument passed to `__init__(text)` must be a string,not <class 'list'>
这是我的代码:
from textblob import TextBlob
from textblob.sentiments import NaiveBayesAnalyzer
blob = TextBlob("This is a horrible idea.",analyzer=NaiveBayesAnalyzer())
blob.sentiment
print(blob.sentiment)
我的列表看起来像这样:
sentences = ['Maria was five years old the first time she heard the word
hello.\n','It happened on a Thursday.\n',]
如何更改此代码以接收整个句子列表,并将输出作为数据帧传递?如果可能的话,我想要这样的东西:
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