Skip to content

Working With Reports

Stijn Debrouwere edited this page May 23, 2015 · 3 revisions

Generating a report

Queries are executed and turned into a report lazily, whenever data is requested. You can also explicitly execute a query and generate a report using the Query#get method.

# will return a query object
profile.core.query.metrics('pageviews').range('yesterday')
# will return a report object
profile.core.query.metrics('pageviews').range('yesterday').get()
# will generate a report object and return its rows -- these
# two are equivalent
profile.core.query.metrics('pageviews').range('yesterday').rows
profile.core.query.metrics('pageviews').range('yesterday').get().rows

Rowwise and columnwise data access

report = query.metrics('pageviews', 'sessions').range('yesterday')
# first ten rows
report.rows[:10]
# work with just session data points
report['sessions'][:10]
report.rows[:10]['sessions']

Shortcuts for simple data structures

# reports with a single value
profile.core.query.metrics('pageviews').range('yesterday').value
# reports with a single metric
profile.core.query.metrics('pageviews').daily('yesterday', days=-10).values
# reports with a single result
query = profile.core.query.metrics('pageviews', 'sessions').range('yesterday')
query.first == query.last

Analyzing data with Pandas

Pandas is a popular data analysis library for Python. Getting data from Google Analytics into a Pandas DataFrame for further analysis is easy, using the as_dataframe method on Report and Query objects:

df = profile.core.query.metrics('pageviews', 'sessions').range(months=-1).as_dataframe()
print(df[df.pageviews > 100000])

Clone this wiki locally