Skip to content

Instantly share code, notes, and snippets.

@austinogilvie
Last active July 24, 2016 14:38
Show Gist options
  • Select an option

  • Save austinogilvie/5376671 to your computer and use it in GitHub Desktop.

Select an option

Save austinogilvie/5376671 to your computer and use it in GitHub Desktop.
import numpy as np
import pandas as pd
import pandas.io.ga as ga
hosts = ['blog.example.com', 'www.example.com']
account_id = "12345678"
# construct a list of filters
# following the regex =~ contains syntax
# documented in the google API docs
filters = ["hostname=~^" + host for host in hosts]
metrics = ['pageviews', 'visitors']
dimensions = ['date','hour']
start_date = "2013-03-06"
end_date = "2013-03-07"
df = ga.read_ga(metrics,
dimensions=dimensions,
start_date=start_date,
end_date=end_date,
account_id=account_id,
parse_dates=[['date', 'hour']],
filters=filters)
hours = df.index.hour
df.groupby(hours).pageviews.describe().unstack(1).ix[:, 1:].plot()
pd.rolling_mean(df.pageviews, window=2).plot()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment