Created
January 24, 2018 09:02
-
-
Save vijayanandrp/b2edb20dbbfde2cdad62836cfc096fd7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.cloud import bigquery | |
import os | |
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'Google Analytics POC.json' | |
client = bigquery.Client() | |
query_job = client.query(""" | |
SELECT | |
CONCAT( | |
'https://stackoverflow.com/questions/', | |
CAST(id as STRING)) as url, | |
view_count | |
FROM `bigquery-public-data.stackoverflow.posts_questions` | |
WHERE tags like '%google-bigquery%' | |
ORDER BY view_count DESC | |
LIMIT 10""") | |
results = query_job.result() # Waits for job to complete. | |
for row in results: | |
print("{} : {} views".format(row.url, row.view_count)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment