Created
April 30, 2020 19:14
-
-
Save focaalvarez/c3a57e4ae4f0d0af516c1070da8ef200 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from pytrends.request import TrendReq | |
pytrend = TrendReq() | |
#for multiple keywords in English | |
list_of_keywords=['champagne','cognac','wine','whisky','vodka'] | |
#for multiple countries | |
list_of_regions=['AT', 'BE', 'BG', 'DE', 'DK', 'EE', 'GB', 'GR', 'HU', 'HR'] | |
#Create tuples of (keyword, country). | |
zip_list = [(i, j) for i in list_of_keywords for j in list_of_regions] | |
data=pd.DataFrame() | |
for i,j in zip_list: | |
pytrend.build_payload(kw_list=[i], | |
timeframe='2018-01-01 2020-04-29', | |
geo=j) | |
df = pytrend.interest_over_time() | |
df['region']=j | |
df['keyword']=i | |
df.reset_index(inplace=True) | |
df.columns=['date','value','isPartial','region','keyword'] | |
data=pd.concat([data,df],ignore_index=True) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment