- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
- Python Advanced Tutorial
- Python - Classes/Objects
- Python - Reg Expressions
- Python - CGI Programming
- Python - Database Access
- Python - Networking
- Python - Sending Email
- Python - Multithreading
- Python - XML Processing
- Python - GUI Programming
- Python - Further Extensions
Twitter Sentiment Analysis using Python
In this article, we will be learning about the twitter sentimental analysis. We will register for twitter oAuth API, install all the dependencies and finally write our sentimental analyzer script.
An API(Application programming interface) is a gateway that allows you to access some servers(Twitter) internal functionality.
The prerequisite is that we have a twitter account set up with a verified phone number.
After this, we visit the Twitter website and tap on the create a new app icon. Now we fill all the credentials i.e. name and accept the developer agreement and finally click on create.
Now our app is created, on the top menu, we will click on the keys tab. Here we will be obtaining our OAuth verification details and all the tokenizers.
Now let's install all the dependencies −
1. tweepy module : >>> pip install tweepy 2. textblob module : >>> pip install textblob
what is textblob?
It is a module used in sentiment analysis. It contains an inbuilt method to calculate sentiments on a scale of -1 to 1.
First, we need all the access tokenizer from the twitter application website as created initially −
#Twitter credentials for the app interface consumer_key = 'xxxxx' consumer_secret = 'xxxx' access_key= 'xxxx' access_secret = 'xxxx'
No, we need to authenticate the credentials via script. For that, we create an authentication variable auth.
now we set the access token with the help of authentication variable
Now we create an API variable to perform our operations
we need to get the public tweets via search method and store it in the form of a list.
public_tweet=api.search('Tutorialspoint') for tweet in public_tweet: print(tweet.text) analysis=TextBlob(tweet.text) print(analysis)
In the output, we observe to thing i.e. the polarity and subjectivity.
Polarity measures how positive or negative some text is.
Subjectivity measures the text that how much it is opinionated as compared to factual.
With the help of this sentiment analyzer, we are able to understand and extract human feelings out of the data.
- Related Articles
- Twitter Sentiment Analysis using Python Program
- Twitter Sentiment Analysis using Python Programming.
- Data analysis using Python Pandas
- Olympics Data Analysis Using Python
- How to Automatically Close Alerts using Twitter Bootstrap?
- Regression Analysis and the Best Fitting Line using Python
- Python Data analysis and Visualization
- Exploratory Data Analysis in Python
- Data Analysis and Visualization in Python?
- How to increase twitter followers?
- Data analysis and Visualization with Python program
- Best ways to improve twitter conversation
- Trend Analysis Vs Ratio Analysis
- Transform Analysis of LTI Systems using Z-Transform
- Explain how Python data analysis libraries are used?