This Python script allows you to analyze the sentiment of tweets based on a specified hashtag using Tweepy and VADER Sentiment Analysis.
Before you begin, ensure you have the following prerequisites:
- Python installed.
- A Twitter Developer account with API access credentials (consumer_key, consumer_secret, access_token, access_token_secret).
- Necessary Python libraries installed using
pip install tweepy pandas numpy matplotlib vaderSentiment
.
-
Clone this repository or download the script:
git clone https://github.com/yourusername/your-repo.git
-
Create a
Twitter_config.py
file in the same directory with your Twitter API credentials:consumer_key = "YOUR_CONSUMER_KEY" consumer_secret = "YOUR_CONSUMER_SECRET" access_token = "YOUR_ACCESS_TOKEN" access_token_secret = "YOUR_ACCESS_TOKEN_SECRET"
-
Run the script:
python twitter_sentiment_analysis.py
-
Enter the hashtag you want to analyze when prompted.
-
The script will fetch tweets containing the specified hashtag, clean the data, perform sentiment analysis using VADER, and display histograms of sentiment scores.
Here's an example of how to use the script:
Type your hashtag: #OpenAI
The script will generate a CSV file tweets.csv
containing the date and cleaned tweet text. It will also display histograms of sentiment scores (Positive, Negative, Compound, and Neutral) using Matplotlib.
This project is licensed under the MIT License. See the LICENSE file for details.