GeneralMills / pytrends

Pseudo API for Google Trends
Other
3.28k stars 821 forks source link

interest_by_region not working at 'CITY' level #342

Open lypticDNA opened 5 years ago

lypticDNA commented 5 years ago

Hi, I am currently building a suite of tools that harness the 'pytrends' scripts and found that the only one that does not appear to work as intended is the 'interest_by_region'.

Below is the part of the script that calls the data, prints it on screen and writes it to a CSV. I have changed the 'resolution' and the data pulled does not change.

pytrends.build_payload(kw_list, geo='GB')
search_df = pytrends.interest_by_region(resolution='CITY', inc_low_vol=True, inc_geo_code=True)
print(search_df)
search_df.to_csv ('C:/.../pyscripts/region.csv')

As you can see below, this is the output I am getting.

                 geoCode  brexit  doomed
geoName
England           GB-ENG     100       0
Northern Ireland  GB-NIR     100       0
Scotland          GB-SCT      99       1
Wales             GB-WLS     100       0

Is this a bug or potential issue with the way Google allows the data to be read?

emlazzarin commented 5 years ago

If you look in the code, you can see that interest_by_region is only implemented for the US:

https://github.com/GeneralMills/pytrends/blob/16492e1610b87cec8248c3c79a0bd97cfb905bee/pytrends/request.py#L256-L261

I think this is a Google limitation, but I'm not sure - I didn't implement it.

Do you think you could modify this code to try regional searches with geo='GB' and see if it works? I'm happy to merge a PR.

lypticDNA commented 5 years ago

Thanks for the comment and recommendation. I tested this and found that it still outputs at country level for GB. You could be correct in stating this may be a Google limitation. I will continue to test the functionality to see if I can identify a solution.

konradbachusz-zz commented 4 years ago

Google trends provides a breakdown by city

MaxGhenis commented 4 years ago

In the interim, it would be helpful to warn users that DMA/CITY/REGION are only implemented for the US at present.

For example, I got a 500 error when using pytrend.interest_by_region(resolution='REGION') without specifying pytrend.build_payload(..., geo='US'). pytrend.interest_by_region(resolution='region') also gives data per country. See this notebook.

To the general point, I think city and region are available outside the US, though DMA may not be.