-
Notifications
You must be signed in to change notification settings - Fork 56
Working With Reports
Stijn Debrouwere edited this page May 23, 2015
·
3 revisions
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().rowsreport = 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']# 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.lastPandas 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])- Authentication
- Querying
- Common Queries
- Working With Reports
- On The Command Line
- Python API documentation