Define the query terms you want to investigate.

In [9]:
QUERY_TERMS = ['dollar', 'bitcoin']

And just press re-run.

In [10]:
import pandas as pd
import json
import re
import urllib2

%pylab inline

QUERY = '' % ",".join(QUERY_TERMS)

data = urllib2.urlopen(QUERY).read()

# We need to do some data cleaning: remove Javascript header+footer, and translate new Date(....,..,..) into YYYY-MM-DD.
header = """// Data table response\ngoogle.visualization.Query.setResponse("""
data = data[len(header):-2]
data = re.sub('new Date\((\d+),(\d+),(\d+)\)', (lambda m: '"%s-%02d-%02d"' % (, 1+int(, int(, data)

timeseries = json.loads(data)
Populating the interactive namespace from numpy and matplotlib
In [11]:
columns = [k['label'] for k in timeseries['table']['cols']]
rows = map(lambda x: [k['v'] for k in x['c']], timeseries['table']['rows'])
df = pd.DataFrame(rows, columns=columns)
df.set_index('Date', inplace=True)
df.plot(figsize=(16, 8))
<matplotlib.axes.AxesSubplot at 0x10f242610>
Back to top