Pytrend to extract interest over time AND by region

110 Views Asked by At

I want to use pytrend to extract the annual interest on Google in absolute value, from 2004 to 2022, with respect to a keyword (e.g. pasta) in Italy divided by "City".

At the moment I Know that there are two functions that allow or to see the time series over time but aggregated or to see the interest by region but aggregated over time ( interest_over_time(), interest_by_region(resolution="COUNTRY")).

Is there a way to have both spatial and temporal dimensions?

Here is the code for the two functions I know of ( interest_over_time(), interest_by_region(resolution="COUNTRY")).

from pytrends.request import TrendReq
# connect to google
pytrends = TrendReq(hl='it-IT', tz=360)
# keywords to search for
pytrends.build_payload(kw_list=['pasta'])

# dataframe
time_df = pytrends.interest_over_time()
print(time_df.tail)
# Interesse per regione
interest_by_region_df = pytrend.interest_by_region(resolution="COUNTRY")#Nazioni del mondo

#looking at rows where all values are not equal to 0
interest_by_region_df = interest_by_region_df[(interest_by_region_df != 0).all(1)]
#drop all rows that have null values in all columns
interest_by_region_df.dropna(how='all',axis=0, inplace=True)

interest_by_region_df.head()
0

There are 0 best solutions below