top of page
Eva Wang

Scrape Google Trends Data

Updated: Sep 7, 2021

Google Trends is a website showing how frequently a given search term is entered into Google’s search engine relative to the site’s total search volume over a given period of time. From Google Trends, you can find the search trend of certain keywords on google. You can also compare the search trends of up to five keywords. For example, below compares five keywords search trends.



The above visualizations might not satisfy your particular needs. If you have the underlying data, you can make your own visualization. This article explains how to scrape data using Python's pytrends library.


Below is the code to scrape the search trend of keywords "dress" and "pants" from Jan 1, 2020 to Jan 10 2020 in British Columbia, Canada.



from pytrends.request import TrendReq
import pandas as pd
import time
pytrend = TrendReq(hl='en-GB', tz=360)

keywords=['dress','pants']
dataset = []

for x in range(0,len(keywords)):
     keyword = [keywords[x]]
     pytrend.build_payload(
 kw_list=keyword,
 cat=0,
 timeframe='2020-01-01 2020-01-10',
 geo='CA-BC')
     data = pytrend.interest_over_time()
 if not data.empty:
          data = data.drop(labels=['isPartial'],axis='columns')   
          dataset.append(data)
 
result = pd.concat(dataset, axis=1)   # merge the dataset using first column as reference
print(result)

The result is:










Do you understand what the result means? The numbers represent the search interest of each keyword relative to the highest point of the same keyword within the period in British Columbia, Canada. A value of 100 is the peak popularity for the term. A value of 50 means that the term is half as popular. A score of zero means there was not enough data for the term.


We can also search the popularity of a term by region within a specific period. Below is an example to find the search popularity of the keyword "yoga pants" from Jan 1, 2016 to Feb 2, 2021 in Canada.



from pytrends.request import TrendReq
pytrend = TrendReq()
pytrend.build_payload(kw_list=['yoga pants'], timeframe='2016-01-01 2021-07-02', geo='CA')
df = pytrend.interest_by_region()
df.reset_index().plot(x='geoName', y='yoga pants', figsize=(8, 5), kind ='bar')





Credits:


13 views0 comments

Comentários


Post: Blog2_Post
bottom of page