My neighbours moved here last year. They work, volunteer, and make this street feel like home.
2019 Canadian Federal Elections Sentiment Analysis
I'm worried immigration targets are rising faster than housing and public services can keep up.
Black newcomers deserve the same chance to build a life here as anyone else.
New immigration targets announced today. Waiting to see how the policy will work.
I don't want Black immigrants moving into my neighbourhood.
We can welcome newcomers and still ask for a plan on housing. Both matter.
I came here for a safer future. I wish people could see us as neighbours first.
I'm tired of every immigration debate turning into an excuse to attack people.
Our newest neighbours brought food to the block party. That's the kind of community I want.
Before raising immigration targets again, show us the housing and school capacity plan.
Being new to a country doesn't make someone less deserving of respect.
How long are work permit applications taking now? Looking for a clear answer.
I think immigration levels should come down until public services catch up.
I support immigration. I also want wages, rent, and access to healthcare taken seriously.
My qualifications count back home. Here I'm starting over. A little patience would mean a lot.
You can disagree about immigration policy without blaming an entire group of people.
Roadmap
Social Media Data Processing & Analysis Pipeline
Research Methodology
5-Stage Data Pipeline & The 5 Ws
- STAGE 1
Data Preparation
- Load & flatten raw JSON data
- Clean tweet text (URLs)
- Standardize timestamp formats
- STAGE 2
Exploratory Data Analysis
- Audit tweet volume and missing data
- Identify frequent keywords
- Refine text cleaning rules
- STAGE 3
Data Transformation
- Identify columns
- Filter migration-related tweets
- Classify actor categories and bot labels
- Create temporal intervals
- Extract & standardize user location
- STAGE 4
Content, Sentiment & Network Analysis
- Generate themes (core topics)
- Conduct tweet-level sentiment analysis
- Identify sentiment across themes
- Determine retweet amplification
- STAGE 5
Visualizations
- Plot temporal tweet and sentiment trends
- Plot overall immigration theme
- Plot location of immigration related tweets
- Plot sentiment across theme, Retweet amplification across themes
THE 5 Ws ANALYTICAL FRAMEWORK ACROSS THE PIPELINE
- WHO
- Actors & Bot Labels (Stages 3–4)
- WHAT
- Keywords & Migration Tweets (Stages 2–4)
- WHEN
- Temporal Intervals (Stage 3)
- WHERE
- User Locations (Stage 3)
- WHY
- Themes & Sentiment (Stage 4)
Content Analysis
Data transformation charts
Lexical Dispersion of Key Terms in 2019 Canadian Election Tweets
Data transformation charts
Election Tweets by User-Reported Location
Immigration- Related and Other Tweets by Time of the Day
Data transformation charts
Bot-Like Behaviour in Immigration-Related Election Tweets by Actor Category
Data transformation charts
Share of Immigration-Related Tweets in the Election Dataset
Sentiment Analysis
What We Are Here to Answer
Q1: Overall Sentiment of Immigration-Related Tweets During the 2019 Canadian Federal Election
Q2: Sentiment Distribution Across Immigration Themes
Q3: Different Meanings of Negative Tweets by Week
Network Data Analysis
Network Data Analysis
Who retweeted whom?
Network analysis
Amplification Diagram

The original circular retweet diagram: 43 accounts and 33 selected links.
Arrows point to original authors. Rankings use the full 1,278-account network.
Who Got Amplified?
Incoming events and distinct retweeters
Top Ten Original Authors
Two Authors Received
455 Retweets.
| Original author | Retweet events received | Distinct retweeters |
|---|---|---|
| @maritstiles | 236 | |
| @sunlorrie | 211 | |
| @macleans | 70 | |
| @cdnpoli_memes | 61 | |
| @QuigginReport | 41 | |
| @TheTorontoSun | 38 | |
| @ctvqp | 39 | |
| @SebBovetSRC | 37 | |
| @WhatAboutMadMax | 33 | |
| @MigrantRightsCA | 32 |
Amplification & Sentiment
3,711 Tweet Events
Overall VADER language labels
| Category | Negative | Positive | Neutral | Total |
|---|---|---|---|---|
| All events | 1,683 | 1,347 | 681 | 3,711 |
25 Negative Messages Reviewed
One cell = one reviewed message
- 36%
- 28%
- 24%
- 12%
Negative language does not establish opposition. A retweet does not establish agreement.
Conclusion
Language
Topics
| Category | Negative | Positive | Neutral | Total |
|---|---|---|---|---|
| Border Security & National Security | 63 | 24 | 14 | 101 |
| Economic Impact & Employment | 38 | 76 | 10 | 124 |
Circulation
Thank You
Thank you for listening Questions are welcome
Open for discussion
Questions about the data, methods or findings are welcome.
With thanks,
The teamReference for Q&A
Appendix
Important transformations.
Open a step for its rules and counting choices.
- 4,966loaded records
- 4,815with tweet text
- 3,711keyword matches
- 1,315included retweets
01Text preparationKeep text. Decode entities. Remove RT headers.
Flatten the JSON with pd.json_normalize. Drop 151 rows where full_text is null, leaving 4,815 records.
Create full_text_Clean by decoding HTML entities and removing the RT @username: header. Retweet events remain in the data.
Stop words and non-alphabetic tokens are removed in a separate column for word frequency and lexical dispersion. VADER uses full_text_Clean, retaining punctuation and stop words.
Notebook cells 2–4, 7–8
02Immigration selectionAt least one English keyword → Yes.
Search the original full_text using a case-insensitive English keyword list. Escape the terms, check longer phrases first and use word boundaries to avoid matches inside longer words.
3,711 records match at least one term; 1,104 match none. Examples include immigration, refugee, work permit and citizenship.
The flag identifies keyword matches. It can miss relevant posts without those terms and does not establish a person's position on immigration.
Notebook cell 11 · Immigration flag check export
03Time & locationUTC → Toronto time. Profile text → region.
Parse created_at as UTC, then convert to America/Toronto. Extract dates, weekdays and hours; group times into eight three-hour windows. Unparseable timestamps become missing values.
Lowercase user.location and match province names, selected cities and abbreviations. For example, Toronto maps to Ontario.
Keep missing or blank locations as No User Location Provided; keep nonblank unmatched locations as Unknown. These are profile descriptions, not verified posting locations.
Notebook cells 10, 12 · Province identification check export
04Account rulesProfile keywords + lifetime posting rate.
Match the account name and biography in this order: government, media, political, civil society. The first matching category wins; unmatched accounts remain Unclassified.
Estimate posts per day as lifetime user.statuses_count divided by account age at the tweet date. Zero or negative account ages become missing.
Flag bot-like behaviour above 50 posts/day, or above 25 with a default image, default profile or empty biography. A missing rate is Not assessed.
These rules provide provisional categories and flags. They do not verify identity or automation.
Notebook cell 20
05Sentiment & themesOne score per tweet ID. Several themes possible.
Score full_text_Clean once per distinct immigration tweet id_str. VADER compound scores ≥ 0.05 are positive, ≤ −0.05 negative; values between them are neutral.
Match seven theme dictionaries, counting each theme once per tweet. Expand the matched list into one row per tweet–theme pair; keep unmatched tweets as Unclassified.
3,711 scored events become 4,691 tweet–theme rows, including Unclassified. Theme totals can exceed event totals. Retweeted copies have their own tweet IDs and contribute separate events.
A negative language score does not establish opposition to immigration.
Notebook cells 22–23, 32–33 · Event and theme sentiment exports
06Retweet networkRetweeter → original author. Repetition → weight.
Use structured posting and original-author handles. Keep one row per tweet ID: 1,325 events have both endpoints. Exclude 10 self-retweets, leaving 1,315 included events.
Group retweeter–author pairs; each pair's event count is its edge weight. This gives 1,283 directed pairs across 1,278 accounts. Incoming events and distinct retweeters are counted separately.
10 RT-prefixed records lack a structured original author and cannot supply an edge. The diagram shows 43 accounts and 33 selected links; rankings use the full network.
Retweets record repetition. They do not establish agreement, audience reach or a causal effect on sentiment.
Notebook cells 59–69 · Network selection checks and edge exports

