Get Google Trends Data into Power BI with Python

As of the time of writing this post, there is no native connector in Power BI for Google Trends API to pull data directly a report. However, we can easily do this with just a few lines of Python code. This will allow you to bring in multiple keywords to compare trends over time. We achieve all this with the PyTrends library. In this tutorial, you will be able to replicate the interactive Google Trends visual in both Power BI and Python.

The video will show you step by step on how to write the code. You can also get the jupyter notebook

#get the Google trends scraper API
from pytrends.request import TrendReq
#add my parameters 
trend = TrendReq(hl='en-US', tz=360)
#keyword list
kw_list  = ['Microsoft','Apple']
#create payload
trend.build_payload(kw_list,timeframe='2021-01-01 2022-01-01')
#create a dataframe of google trends
data = trend.interest_over_time()

This code snippet will give you a data frame of the Google Trends data for Microsoft and Apple. You can visualize this with Plotly or import the script in to Power BI.

Gaelim Holland

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments