Google Trends with Python
· 686
Wajdi Alkayal Wajdi Alkayal

Thinking these days how we probably started to value more building blocks of our existence. As it started to feel more integrated into our existence as follows - health, water, food and often mentioned Covid that limited our ability to travel for some regions. To have overall knowledge of how does it goes worldwide there is well known Google Trends online tool to work with. But there is something special for those who are in love with Python. Beautiful graphing library Plotly licensed under the MIT license.

Scripts to Download

Here is a simple installation prepared to work with on my GitHub repository with a requirements.txt file and a short script to plot data into a nice histogram data form. Simply download these two files as follows so save these to your desktop into some working directory google-trends-analysis.py and requirements.txt Create a directory named google-trends-analysis and save these files into.

Activate Virtualenv

I do assume you already have virtualenv installed, but if not just execute sudo pip3 install virtualenv. Enter into google-trends-analysis directory with cd google-trends-analysis.

cd google-trends-analysis

To make all stuff properly done activate virtualenv with the creation of working virtual environment directory called venv.

virtualenv venv 

Your google-trends-analysis directory looks like now like on picture hereunder.

Image description

Now activate this working environment.

source venv/bin/activate

Pytrends and Plotly Libraries to Install

All libraries needed to run Google Trends and Plotly correctly are saved in requirements.txt file. Now execute installation in a virtual environment we already activated.

pip3 install -r requirements.txt

This will take a while to pass all installations. You'll see in your terminal how all libraries are installed to properly run the script.

After installation to run google-trends-analysis.py script hereunder just type this command and enjoy response in your browser IP 127.0.0.1 on a random port.

python3 google-trends-analysis.py

This is how it will look like, a nicely plotted graph in the final result. (Graph images by author)

Image description

Image description


Related Posts
Graphic design
09 June
The Power of Email Marketing
03 June
Photography
01 June

WMK Tech Copyright © 2024. All rights reserved