Python Textblob过度概括文本并将其分类为中性文本
我使用textblob来确定twitter文本的情绪,但有些结果没有极性和主观性(使它们成为中性情绪)- ) 我的代码在下面Python Textblob过度概括文本并将其分类为中性文本,python,nlp,sentiment-analysis,textblob,Python,Nlp,Sentiment Analysis,Textblob,我使用textblob来确定twitter文本的情绪,但有些结果没有极性和主观性(使它们成为中性情绪)- ) 我的代码在下面 # Create a function to get the subjectivity def getSubjectivity(text): return TextBlob(text).sentiment.subjectivity # Create a function to get the polarity def getPolarity(text):
# Create a function to get the subjectivity
def getSubjectivity(text):
return TextBlob(text).sentiment.subjectivity
# Create a function to get the polarity
def getPolarity(text):
return TextBlob(text).sentiment.polarity
# Create two new columns 'Subjectivity' & 'Polarity'
df['Subjectivity'] = df['Tweets'].apply(getSubjectivity)
df['Polarity'] = df['Tweets'].apply(getPolarity)
# Show the new dataframe with columns 'Subjectivity' & 'Polarity'
df
# Subjectivity < 1 but > 0 is more factual, > 1 is very opinionated (0 and +1 are min/max)
# Polarity < 0 is more negative, > 0 is more positive (-1 and +1 are the min/max)
#创建一个函数以获取主观性
定义(文本):
返回TextBlob(text.touction.com)
#创建一个函数来获取极性
def getPolarity(文本):
返回TextBlob(text).emotional.polarity
#创建两个新列“主观性”和“极性”
df['substantical']=df['Tweets'].apply(getsubstantical)
df['Polarity']=df['Tweets'].apply(getPolarity)
#显示带有“主观性”和“极性”列的新数据帧
df
#主观性<1但>0更符合事实,>1非常固执己见(0和+1为最小值/最大值)
#极性<0表示更负,>0表示更正(-1和+1表示最小值/最大值)
情绪分析分类代码-#创建一个函数来计算负(-1)、中性(0)和正(+1)分析定义getAnalysis(分数):如果分数<0:返回“负”elif分数==0:返回“中性”否则:返回“正”df[“分析”]=df[“极性”]。应用(getAnalysis)#显示数据框
请不要在评论中发布代码-它简直无法阅读!改为编辑并更新您的问题。