标签:apply input osi you following contain asc amp down
参考:Tutorial: Quickstart - TextBlob (sentiment analysis)
参考:An overview of sentiment analysis python library: 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
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‘
标签:apply input osi you following contain asc amp down
原文地址:https://www.cnblogs.com/alex-bn-lee/p/14257912.html