In recent months, Joe Biden's public sentiment has seen significant fluctuations, largely influenced by key political events. By analyzing data scraped from Reddit, we can gain insights into how these events impacted public opinion. Here, we'll delve into the sentiment trends observed from January to July 2024, focusing on two major events: the assassination attempt on Donald Trump on July 13th and Joe Biden's withdrawal from the 2024 election on July 21st.
Tools and Libraries Used
To perform this analysis, I employed several Python libraries, including:
- Pandas for data manipulation and cleaning.
- Matplotlib and Plotly for data visualization.
- NLTK (Natural Language Toolkit) for sentiment analysis.
- Reddit API for scraping the data.
Let's walk through the process step by step.
Data Collection
The first step involved collecting comments related to Joe Biden from Reddit. Using the Reddit API, I scraped data from various subreddits, ensuring a comprehensive dataset. Here's a snippet of the code used for scraping:
import praw
reddit = praw.Reddit(client_id='your_client_id',
client_secret='your_client_secret',
user_agent='your_user_agent')
subreddit = reddit.subreddit('politics')
comments = []
for comment in subreddit.comments(limit=1000):
comments.append(comment.body)
Data Cleaning
Once the data was collected, the next step was to clean it. This involved removing duplicates, null values, and irrelevant data. I used Pandas to accomplish this:
import pandas as pd
df = pd.DataFrame(comments, columns=['comment'])
df.drop_duplicates(inplace=True)
df.dropna(inplace=True)
Sentiment Analysis
To analyze the sentiment of each comment, I used the VADER sentiment analysis tool from the NLTK library. VADER is specifically attuned to sentiments expressed in social media:
from nltk.sentiment.vader import SentimentIntensityAnalyzer
sid = SentimentIntensityAnalyzer()
df['sentiment'] = df['comment'].apply(lambda x: sid.polarity_scores(x)['compound'])
The sentiment scores range from -1 (most negative) to 1 (most positive). For this analysis, comments with a score less than 0 were classified as negative.
Data Visualization
I visualized the data using Matplotlib and Plotly to create insightful graphs.
Frequency of Negative Sentiments (January to July 2024)
The first graph shows the frequency of negative comments from January to July 2024. Here's a detailed analysis of the trends:
- January to March 2024: The early months saw sporadic spikes in negative sentiments, with a notable peak in March. This period coincided with various political maneuvers and policy decisions, likely contributing to the mixed reactions.
- April to May 2024: The negative sentiment frequency remained relatively moderate during these months. There were occasional spikes, but they did not reach the high levels seen in March. This period might have been relatively stable politically, leading to fewer negative comments.
- June to July 2024: A noticeable increase in negative sentiments began in late June, peaking in early July. This surge correlates with the build-up to the assassination attempt on Donald Trump on July 13th. The incident caused a significant outpouring of negative comments, likely reflecting public fear and uncertainty. Following the assassination attempt, the frequency of negative sentiments remained high, peaking again around July 21st when Joe Biden announced his withdrawal from the 2024 presidential race. This major political shift likely fueled public discourse, leading to increased negative sentiments.
Daily Average Sentiment Score (July 2024)
The second graph illustrates the daily average sentiment score for Joe Biden in July 2024. Let's break down the key observations:
- Early July: The sentiment score remained relatively stable and positive at the beginning of the month. Public sentiment towards Biden was generally favorable, with a few minor fluctuations.
- July 13th (Trump Assassination Attempt): After the assassination attempt on Trump, there was a noticeable dip in Biden's sentiment score. The event caused a surge in negative comments, reflecting the heightened tension and fear within the public.
- July 21st (Biden's Withdrawal from 2024 Election): Following Biden's withdrawal announcement, the sentiment score saw a significant increase. This upward trend suggests that Biden's decision was met with a mixture of relief and approval from the public, possibly due to the political climate and the public's perception of Biden's presidency.
Conclusion
The analysis of Reddit data provides valuable insights into how public sentiment towards Joe Biden has evolved over recent months. The assassination attempt on Donald Trump and Biden's subsequent withdrawal from the 2024 election were pivotal events that significantly impacted public opinion.
While the assassination attempt led to a surge in negative comments and a drop in sentiment score, Biden's withdrawal appeared to have the opposite effect, increasing positive sentiment. These trends highlight the dynamic nature of public opinion and the influence of major political events on sentiment.
By continuously monitoring and analyzing such data, we can better understand the public's reaction to political developments and anticipate potential shifts in sentiment. This analysis serves as a testament to the power of data analytics in revealing the underlying trends in public opinion.