8. Sentiment Analysis
Activity 8.01: Tweet Sentiment Analysis Using the textblob library
Solution
To perform sentiment analysis on the given set of tweets related to airlines, follow these steps:
- Open a Jupyter Notebook.
- Insert a new cell and add the following code to import the necessary libraries:
import pandas as pd from textblob import TextBlob import re
- Since we are displaying the text in the notebook, we want to increase the display width for our DataFrame. Insert a new cell and add the following code to implement this:
pd.set_option('display.max_colwidth', 240)
- Now, load the
airline-tweets.csv
dataset. We will read this CSV file using pandas'read_csv()
function. Insert a new cell and add the following code to implement this:tweets = pd.read_csv('data/airline-tweets.csv')
- Insert a new cell and add the following code to view the first 10 records of the DataFrame:
tweets.head()
The code generates the following output: