首页 > 其他 > 详细

【520】利用 TextBlob 进行情感分析

时间:2021-01-10 15:22:31      阅读:103      评论:0      收藏:0      [点我收藏+]

参考:Tutorial: Quickstart - TextBlob (sentiment analysis)

参考:An overview of sentiment analysis python library: TextBlob

参考:How does TextBlob calculate sentiment polarity? How can I calculate a value for sentiment with machine learning classifier?

1. Installation of TextBlob

  Installation is not a big deal here. If you are already using CMD, you have to run this command to install TextBlob. Go to CMD and enter:

pip install textblob

  

  You need to download corpus first to train the model of TextBlob. You can achieve it using the following command:

python -m textblob.download_corpora

  

2. Steps for Sentiment Analysis Python using TextBlob

  Here is a sample code of how I used TextBlob in tweets sentiments:

from textblob import TextBlob
### My input text is a column from a dataframe that contains tweets. 

def sentiment(x):
    sentiment = TextBlob(x)
    return sentiment.sentiment.polarity

tweetsdf[‘sentiment‘] = tweetsdf[‘processed_tweets‘].apply(sentiment)
tweetsdf[‘senti‘][tweetsdf[‘sentiment‘]>0] = ‘positive‘
tweetsdf[‘senti‘][tweetsdf[‘sentiment‘]<0] = ‘negative‘
tweetsdf[‘senti‘][tweetsdf[‘sentiment‘]==0] = ‘neutral‘

  

【520】利用 TextBlob 进行情感分析

原文:https://www.cnblogs.com/alex-bn-lee/p/14257912.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!