问题描述
我需要您的帮助,因为我尝试了所有方法,但无法使用 TextBlob 对从数据帧中的推文中提取的名词短语执行情感分析。另外我认为 TextBlob.noun_phrases 函数没有产生正确的结果。请在下图中亲自查看。我真的是 Python 新手,请帮忙!!
from textblob import TextBlob
nltk.download('wordnet')
nltk.download('brown')
nltk.download('punkt')
def blob(text):
return TextBlob(text).noun_phrases
df['Noun_Phrases'] = df['Tweets'].apply(blob)
df
def getsubjectivity(text):
return TextBlob(text).sentiment.subjectivity
df['Subjectivity'] = df['Noun_Phrases'].apply(getsubjectivity)
错误:类型错误:传递给 text
的 __init__(text)
参数必须是字符串,而不是
解决方法
不确定您的目标。在您的 getsubjectivity
函数中,输入必须是字符串,似乎您正在为它提供一个列表。
如果您进行以下更改,您将克服错误。
def getsubjectivity(text):
text=''.join(text)
return TextBlob(text).sentiment.subjectivity