8. Sentiment Analysis
Activity 13: Tweet Sentiment Analysis Using the TextBlob library
Solution
Let's perform sentiment analysis on tweets related to airlines. Follow these steps to implement this activity:
- 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 we load the
Tweets.csv
dataset. From this dataset, we are only fetching the "text
" column. Thus, we need to mention the "text
" column name as the value for theusecols
parameter of theread_csv()
function. The fetched column is later being replaced to a new column named "Tweet
". Insert a new cell and add the following code to implement...