How to do a perfect Twitter sentiment analysis using Twitter API
Have you ever wondered how to do a perfect Twitter sentiment analysis using Twitter API? I will show below the whole process step by step.
The aim is to analyse and to preprocess the tweets using Twitter API. The goal is to analyse individual tweets as positive, negative and neutral and illustrate the sentiment with a word cloud and bar graph.
In the sentiment analysis and using TextBlob, the difference between polarity and subjective is that polarity is a float in the range of -1 to 1. Number 1 means a positive statement and -1 means a negative statement. The polarity indicates sentiment with a value from -1 (negative) to 1 (positive). And 0 is neutral.
It is important to note that subjective sentences generally refer to personal opinion, emotion or judgment whereas objective refers to factual information. Subjectivity is also a float in the range from 0 to 1. The subjectivity is a value from 0 (objective) to 1 (subjective).
Steps are following:
Step 1: Importing libraries
Step 2: Creating Twitter API
Step 3: Authenticate Twitter API
Step 4: Accessing tweets
Step 5: Printing recent tweets
Step 6: Extracting english and finnish tweets only
Step 7: Getting tweets with keyword, hashtags or trending items also insted of some user name
Step 8: Creating dataframe
Step 9: Creating function to clean and remove unwanted text or symbols
Step 10: Getting subjectivity and polarity
Step 11: Plotting word cloud
Step 12: Plotting scatter graph between polarity and subjectivity
Step 13: Plotting positive and negative tweets using bar graph
Please find the whole process with code in a notebook found in my github repo: https://github.com/markok20/Twitter-API/blob/main/How%20to%20do%20a%20Twitter%20sentiment%20analysis%20using%20Twitter%20API%20GH%20(1).ipynb