---
title: How to Use Data Science to Assess Public Opinion
description: Here's how I used data science to assess public opinion on Twitter.
image: https://blog.avenuecode.com/hubfs/image%20(7).png
---

[AvenueCode.com](https://avenuecode.com) [News](https://avenuecode.com/news) [Contact](https://avenuecode.com/contact)

[![Avenue Code Snippets Logo](https://blog.avenuecode.com/hubfs/Avenue%20Code%20New%20Logos%20-%202023/AC-Snippets---Black.png)](https://blog.avenuecode.com/?hsLang=en-us) *menu*

- Technology
  
  [Cloud](https://blog.avenuecode.com/blog/topic/cloud?hsLang=en-us) [Delivery Infrastructure](https://blog.avenuecode.com/blog/topic/delivery-infrastructure?hsLang=en-us) [Web Experience](https://blog.avenuecode.com/blog/topic/web-experience?hsLang=en-us) [Agile Mindset](https://blog.avenuecode.com/blog/topic/agile-mindset?hsLang=en-us) [Quality First](https://blog.avenuecode.com/blog/topic/quality-first?hsLang=en-us)
  
  [Design](https://blog.avenuecode.com/blog/topic/design?hsLang=en-us) [Solution Architecture](https://blog.avenuecode.com/blog/topic/solution-architecture?hsLang=en-us) [Data & ML](https://blog.avenuecode.com/blog/topic/data-and-machine-learning?hsLang=en-us) [Mobile Experience](https://blog.avenuecode.com/blog/topic/mobile-experience?hsLang=en-us)
- [Whitepapers](https://blog.avenuecode.com/blog/topic/whitepapers?hsLang=en-us)
- [Spotlight](https://blog.avenuecode.com/blog/topic/spotlight?hsLang=en-us)
- [Extraordinary Women in Tech](https://blog.avenuecode.com/blog/topic/extraordinary-women-in-tech?hsLang=en-us)
- [Avenue Code Culture](https://blog.avenuecode.com/blog/topic/avenue-code-culture?hsLang=en-us)

- [Cloud](https://blog.avenuecode.com/blog/topic/cloud?hsLang=en-us)
- [Design](https://blog.avenuecode.com/blog/topic/design?hsLang=en-us)
- [Delivery Infrastructure](https://blog.avenuecode.com/blog/topic/delivery-infrastructure?hsLang=en-us)
- [Solution Architecture](https://blog.avenuecode.com/blog/topic/solution-architecture?hsLang=en-us)
- [Web Experience](https://blog.avenuecode.com/blog/topic/web-experience?hsLang=en-us)
- [Data & ML](https://blog.avenuecode.com/blog/topic/data-and-machine-learning?hsLang=en-us)
- [Agile Mindset](https://blog.avenuecode.com/blog/topic/agile-mindset?hsLang=en-us)
- [Mobile Experience](https://blog.avenuecode.com/blog/topic/mobile-experience?hsLang=en-us)
- [Quality First](https://blog.avenuecode.com/blog/topic/quality-first?hsLang=en-us)
- [Whitepapers](https://blog.avenuecode.com/blog/topic/whitepapers?hsLang=en-us)
- [Spotlight](https://blog.avenuecode.com/blog/topic/spotlight?hsLang=en-us)
- [Extraordinary Women in Tech](https://blog.avenuecode.com/blog/topic/extraordinary-women-in-tech?hsLang=en-us)
- [Avenue Code Culture](https://blog.avenuecode.com/blog/topic/avenue-code-culture?hsLang=en-us)

# [How to Use Data Science to Assess Public Opinion](https://blog.avenuecode.com/how-to-use-data-science-to-assess-public-opinion)

- [Tweet](https://twitter.com/share)

*perm\_identity* [Marcio Viegas](https://blog.avenuecode.com/how-to-use-data-science-to-assess-public-opinion/author/marcio-viegas?hsLang=en-us)

*schedule* 9/9/20 2:00 PM

On a pre-COVID-19 Friday night, I decided to stay in and study data science instead of attending a public celebration. I  started with the ["Complete Data Science Training: Mathematics, Statistics, Python, Advanced Statistics in Python](https://www.udemy.com/course/the-data-science-course-complete-data-science-bootcamp/)," and then decided to look into [Google Cloud Platform](https://cloud.google.com/) as well.

On Saturday, I woke up and decided to skip the festival again, preferring instead to study data science and GCP. Coincidentally, I had been wondering how many other locals felt like they would rather stay in than join the celebration, and I decided to utilize my data science studies to gain a better understanding of general public opinion. 

My first and only idea, based on some previous work developed by my teammates at Avenue Code, was to capture Tweets using the [Filte](https://developer.twitter.com/en/docs/labs/filtered-stream/overview)[red Stream](https://developer.twitter.com/en/docs/labs/filtered-stream/overview) provided by Twitter, then analyze the content's feeling using [GCP Natural Language API.](https://cloud.google.com/natural-language?hl=pt-br) 

I quickly designed some architecture that was [simple](https://en.wikipedia.org/wiki/KISS_principle) but would do the job flawlessly. Besides the two services mentioned, I also used [GCP Pub/Sub](https://cloud.google.com/pubsub/?hl=pt-br) and [GCP Firestore,](https://cloud.google.com/firestore) as shown below:

 

![Sentiments Architecture.png](https://mail.google.com/mail/u/1?ui=2&ik=bba35baf36&attid=0.1&permmsgid=msg-f:1659747774459163439&th=17089bcea162332f&view=fimg&sz=s0-l75-ft&attbid=ANGjdJ-XMHC-3NGLK-KfAcFDhoxwgwR7tilUYdmdoHUR3AkpoAolvF1NRE37zk3PEZ6nzPONFt9QEdUFsZDmefTNH8IQERP4VI_SBdVGRTmNbUsg2coDEjp5IDai-vE&disp=emb&realattid=ii_k75l0obi1)

 

I could have used [GCP Functions](https://cloud.google.com/functions?hl=pt-br) to avoid running code directly in my machine. I guess I thought about that when I was designing the solution - go all serverless, right? - but the time taken to learn one more service  wasn't worth the pay off in this [POC](https://en.wikipedia.org/wiki/Proof_of_concept).

Almost 10k Tweets later, I plotted the information using [ChartJS](https://www.chartjs.org/). The x-axis represents the feeling of the Tweet. Dots closer to the number 1 represent a positive feeling, and dots closer to the number -1 represent the opposite. The y-axis represents the intensity of the discourse. The higher the number, the more intense the feeling is. The result was simple and effective:

![carnival-1](https://blog.avenuecode.com/hs-fs/hubfs/carnival-1.jpg?width=542&name=carnival-1.jpg)

Since this was a purely experimental assessment, I didn't spend too much time analyzing the results. It's a well-known phrase that: "worse than no data is data without context." The circumstances in which I obtained the information are so unique that we could end up in [Simpson's Paradox](https://en.wikipedia.org/wiki/Simpson%27s_paradox#:~:text=Simpson's%20paradox%2C%20which%20goes%20by,when%20these%20groups%20are%20combined.). That said, the premise of my study was relatively simple and had the potential to yield effective results.  

The code is provided in this [repository](https://github.com/marcioviegas/sentiments) within the MIT License. 

---

### Author

# Marcio Viegas

 Marcio Viegas is a Technical Manager at Avenue Code. He loves learning and is passionately curious. He enjoys studying different subjects that could be related to technology or not and considers that his greatest and most valuable professional skill is his ability to bring together his diverse knowledge and creativity to propose solutions for complex problems.

---

### Related Posts

### Efficiently Managing Master and Reference Data

[READ MORE](https://blog.avenuecode.com/efficiently-managing-master-and-reference-data?hsLang=en-us)

### Testing Data Pipelines with Behavior Driven Development (BDD)

[READ MORE](https://blog.avenuecode.com/testing-data-pipelines-with-behavior-driven-development?hsLang=en-us)

### Pillars of the Cloud Center of Excellence (CCoE)

[READ MORE](https://blog.avenuecode.com/cloud-center?hsLang=en-us)

### Data: An Executive Briefing

[READ MORE](https://blog.avenuecode.com/data-an-executive-briefing?hsLang=en-us)

### Leave a Comment!

### Avenue Code Social

[![Facebook Icon](https://blog.avenuecode.com/hubfs/Images/Blog/facebook.png?t=1486470796564)](https://www.facebook.com/avenuecode)

[![Twitter Icon](https://blog.avenuecode.com/hubfs/Images/Blog/twitter.png?t=1486470796842)](https://twitter.com/AvenueCode)

[![LinkedIn Icon](https://blog.avenuecode.com/hubfs/Images/Blog/linkedin.png?t=1486470796556)](https://www.linkedin.com/company/avenue-code)

### Newsletter

Want to stay on top of all tips and news from Avenue Code?

### Popular Snippets

![Primary Logo AvenueCode Inverted.png](https://blog.avenuecode.com/hs-fs/hubfs/Images/Logos/Primary%20Logo%20AvenueCode%20Inverted.png?width=1104&name=Primary%20Logo%20AvenueCode%20Inverted.png "Primary Logo AvenueCode Inverted.png")

### About Us

- [Who We Are](https://www.avenuecode.com/who-we-are)
- [What We Do](https://www.avenuecode.com/what-we-do)
- [Portfolio](https://www.avenuecode.com/portfolio)
- [Partners](https://www.avenuecode.com/partners)
- [News](https://www.avenuecode.com/news)
- [Events](https://www.avenuecode.com/events)
- [Blog](https://blog.avenuecode.com/)
- [Contact](https://www.avenuecode.com/contact)

### Our Offices

San Francisco

[+1 415 766 4178](tel:+553125161448) [ac.inquiries@avenuecode.com](mailto:brazil.info@avenuecode.com)

Belo Horizonte

[+55 31 2516 1448](tel:+553125161448) [brazil.info@avenuecode.com](mailto:brazil.info@avenuecode.com)

São Paulo

[+55 11 3205 3232](tel:+553125161448) [brazil.info@avenuecode.com](mailto:brazil.info@avenuecode.com)

### We're Hiring!

- [Belo Horizonte](https://www.avenuecode.com/who-we-are)
- [New York](https://www.avenuecode.com/what-we-do)
- [San Francisco](https://www.avenuecode.com/portfolio)
- [São Paulo](https://www.avenuecode.com/partners)

---

©2015 - 2017 Avenue Code

[![Facebook Icon](https://blog.avenuecode.com/hubfs/Images/Icons/facebook-2.png)](https://www.facebook.com/avenuecode) [![Twitter Icon](https://blog.avenuecode.com/hubfs/Images/Icons/twitter-2.png)](https://twitter.com/AvenueCode) [![LinkedIn Icon](https://blog.avenuecode.com/hubfs/Images/Icons/linkedin-2.png)](https://www.linkedin.com/company/avenue-code) [![Glassdoor Icon](https://blog.avenuecode.com/hubfs/Images/Icons/glassdoor-icon-1.png)](https://www.glassdoor.com/Overview/Working-at-Avenue-Code-EI_IE456173.11,22.htm) [![YouTube Icon](https://blog.avenuecode.com/hubfs/Images/Icons/youtube-2.png)](https://www.youtube.com/user/AvenueCodePlay)

Please enable JavaScript to view the [comments powered by Disqus.](http://disqus.com/?ref_noscript)

© 2026 Avenue Code

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Marcio Viegas",
    "url" : "https://blog.avenuecode.com/author/marcio-viegas"
  },
  "dateModified" : "2020-09-09T17:00:00.342Z",
  "datePublished" : "2020-09-09T17:00:00.000Z",
  "headline" : "How to Use Data Science to Assess Public Opinion",
  "image" : [ "https://blog.avenuecode.com/hubfs/image%20(7).png" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.avenuecode.com/how-to-use-data-science-to-assess-public-opinion",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.avenuecode.com/hubfs/Avenue%20Code%20New%20Logos%20-%202023/Avenue%20Code-primary%20versions_LOGO%20HORIZONTAL%20group%201-7.png"
    },
    "name" : "Avenue Code"
  }
}
```