码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2021-01-12 11:07:20      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:apply   input   osi   you   following   contain   asc   amp   down   

参考: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 进行情感分析

标签:apply   input   osi   you   following   contain   asc   amp   down   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!