WillKoehrsen / Data-Analysis

Data Science Using Python
https://medium.com/@williamkoehrsen/
MIT License
5.16k stars 3.64k forks source link

Search Terms not Coming Up when google trends has them #24

Closed MacroMuppet closed 5 years ago

MacroMuppet commented 5 years ago

Hi! Thanks for all your work. Great script.

When analyzing the CHGG stock vs search term Chegg I get an error ( full error below).

It doesn't give the failed "There are no search terms" because there are search terms ( link to term, https://trends.google.com/trends/explore?date=today%205-y&geo=US&q=chegg ).

But it won't take that search results and index it to the chart... it works for AMZN and Microsoft and broader search terms ie (college) but it yields electoral college, and college football as search terms.

Thanks for all your help in advance.


AttributeError Traceback (most recent call last)

in ----> 1 chegg.changepoint_date_analysis(search = 'chegg') ~\Projects\stocker.py in changepoint_date_analysis(self, search) 779 780 print('\n Top Related Queries: \n') --> 781 #print(related_queries[search]['top'].head()) 782 783 print('\n Rising Related Queries: \n') AttributeError: 'NoneType' object has no attribute 'head'
MacroMuppet commented 5 years ago

Fixed. Original Code:.... Line 688 pytrends.build_payload(kw_list, cat=0, timeframe=date_range[0], geo='', gprop='news')

Fixed Code (DELETE BOLD).... Line 688 pytrends.build_payload(kw_list, cat=0, timeframe=date_range[0], geo='', gprop='news')

WillKoehrsen commented 5 years ago

Yes, I setup pytrends to search for news by default. If you are searching for a topic that won't appear in the news, you'll need to change the code. Thanks for the fix!