Open giuspataro opened 5 years ago
A quick fix would be in request.py
change
if self.geo == '':
self.interest_by_region_widget['request'][
'resolution'] = resolution
elif self.geo == 'US' and resolution in ['DMA', 'CITY', 'REGION']:
self.interest_by_region_widget['request'][
'resolution'] = resolution
to
if self.geo == '':
self.interest_by_region_widget['request'][
'resolution'] = resolution
elif resolution in ['DMA', 'CITY', 'REGION']:
self.interest_by_region_widget['request'][
'resolution'] = resolution
and change
if (df.empty):
return df
# rename the column with the search keyword
df = df[['geoName', 'geoCode', 'value']].set_index(
['geoName']).sort_index()
to
if (df.empty):
return df
# rename the column with the search keyword
df = df[['geoName', 'value']].set_index(
['geoName']).sort_index()
# split list columns into seperate ones, remove brackets and split on comma
I am considering creating a pull request.
Thanks
In my context (asking for a non US place), the solution worked (only change the second part: removed the geocode)
Just wonder does anyone get this fixed? I had change these 2 section as mentioned above, but still getting the same error:
KeyError Traceback (most recent call last)
I've tried to replicate the issue but the original code from @giuspataro now works:
from pytrends.request import TrendReq
pytrends = TrendReq(hl='en-US', tz=360)
kw_list = ["Blockchain"]
pytrends.build_payload(kw_list, cat=0, timeframe='all', geo='', gprop='')
a = pytrends.interest_by_region(resolution='CITY', inc_low_vol=True, inc_geo_code=False)
print(a)
Output:
Blockchain
geoName
Abeokuta 21
Abidjan 4
Abuja 7
Accra 10
Addis Ababa 2
... ...
Woluwe-Saint-Pierre 5
Yaounde 5
Yonkers 4
Zoetermeer 2
tx. An Nhơn 0
[200 rows x 1 columns]
hello, I'm trying to make a research on city level. I've started with classic case 'Blockchain' as test. My code is:
This reqeust gives me
So does not work. If I specify in payload
geo='IT
only gives me regional level (even if I specify "CITY" resolution) (I have to search interest only on city in italy) while if I use "COUNTRY" resolution works well, even without geo specification (but I do not need it). I saw can be related to #189 (no trend data)) but I do not know how to fix request file. Any advice?Thank you