Programmatic Google Trends API

Updated October 21, 2009

Yesterday, Google released an update to their popular Google Trends tool. There are improvements over the previous version, but the biggest new feature is a new shiny button that lets you download all your data in the format of a CSV. This is a very cool enhancement. Where Google Trends was a geeky toy, it now takes the leap to integrate into analysts’ reports and with that, edge its way onto managerial desks.

This python module is a quasi-API to make it easier to authenticate into Google Trends for those who want to squeeze the extra level of functionality out of their data. The advantage of programmatic access is that the data can be automatically trended and merged. It can be snuck into a 9:00 AM daily email to the VP of Marketing so that she knows to ramp up Google Adwords campaigns for some specific keyword. Also, by programatically pulling multiple reports, it is possible to create a wealth of data not visible in a single report. Using one keyword as a benchmark to merge multiple reports, we can do a meaningful comparison on tens or hundreds of relevant keywords.

To use the pyGTrends, the quasi-Google-Trends-API, you can download the latest version from github.

Here is an example of the most basic basic report that you can pull down from Google Trends. The connector function needs authentication info, and download_report needs to be passed a list of keywords.

[sourcecode language="python" light="true"] from pyGTrends import pyGTrends

connector = pyGTrends('google username','google password') connector.download_report(('keyword1', 'keyword2')) print connector.csv() [/sourcecode]

You can, however, use pyGTrends to get any slice of data that you can pull down from Google Trends. To see the exact parameters that you should use, go to Google Trends, and navigate to the specific sufficiently-narrow report that you are interested in. Then, right-click on the CSV download, and save the link location. The different parameters should be discernible from the link. The following code downloads a report for banana, bread, and bakery keywords from April 2008, originating from the magnificent nation of Austria, and scaled using fixed scaling (aka the second download link).

[sourcecode language="python" light="true"] connector.download_report(('banana', 'bread', 'bakery'), date='2008-4', geo='AT', scale=1) [/sourcecode]

By default, the csv() function downloads the main part of the report, but there are a few additional parts stuck to the bottom of the CSV file. If you are interested in those, pass the section parameter to the csv() function. The following will return the Language section.

[sourcecode language="python" light="true"] print connector.csv(section='Language') [/sourcecode]

Full recommended usage includes using either the csv.reader or csv.DictReader module.

[sourcecode language="python" light="true"] from csv import DictReader print DictReader(connector.csv().split('\n')) [/sourcecode]

Google Trends Eye-Candy

Here is a snapshot from the new Google Trends to add some eye-candy to the post:

Analytics Roundup

Nielsen/NetRatings’ August social media numbers: Not much change
Interesting post I stumbled on related to Nielsen’s web analytics service. Several references to "juicy" or "juiciness".

Inbox Zero
Merlin Mann on cleaning your e-mail inbox.

The New York Times > Home Prices Across the Nation
The most interesting / important part may be the talking head in the lower left, should you be annotating your reports with video?

Introduction to Statistical Thought—free ebook
1) explains how statisticians think about data
2) introduces modern statistical computing
3) as lots of real examples

Analytics Roundup: Chicken presentation and so much more

Programming Collective Intelligence
Pulling information from community contributed data.

Videos that can change your organization
Top ten business videos on YouTube.

The Encyclopedia of Business Cliches

UC Berkeley CS160 User Interfaces Fall 06
Course readings and student notes.

Language Log: Chicken: the PowerPoint Presentation
The presentation you dare not give.

Prometheus Meets the Enterprise Management System
I laughed, I cried, I laughed again.

Diagrams: Tools and Tutorials

Data Visualization: Modern Approaches
A grab bag of ideas.

fontblog : Introducing Ambiguity
A typographic symbol to indicate ambiguity, compare to the typographic mark lol which indicates stupidity.

Whimsley: The Netflix Prize: 300 Days Later

Process Trends Website
Good excel charting and visualization tips.

BusinessWeek: Who Participates And What People Are Doing Online
A simple and fairly effective use of square pies.