The textblob library
textblob
is a Python library used for NLP, as we've seen in the previous chapters. It has a simple API and is probably the easiest way to begin with sentiment analysis. textblob
is built on top of the NLTK library but is much easier to use. In the following sections, we will do an exercise and an activity to get a better understanding of how we can use textblob
for sentiment analysis.
Exercise 8.01: Basic Sentiment Analysis Using the textblob Library
In this exercise, we will perform sentiment analysis on a given text. For this, we will be using the TextBlob
class of the textblob
library. Follow these steps to complete this exercise:
- Open a Jupyter notebook.
- Insert a new cell and add the following code to implement to import the
TextBlob
class from thetextblob
library:from textblob import TextBlob
- Create a variable named
sentence
and assign it a string. Insert a new cell and add the following code to implement this:sentence = "but...