Created
June 2, 2019 05:10
-
-
Save guerbai/7df3aab9c9d0c66c32eb59beb530c84b to your computer and use it in GitHub Desktop.
bigquery safequery #BigQuery
This file contains 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
# Query to select comments that received more than 10 replies | |
query_popular = """ | |
SELECT parent, COUNT(id) | |
FROM `bigquery-public-data.hacker_news.comments` | |
GROUP BY parent | |
HAVING COUNT(id) > 10 | |
""" | |
# Set up the query (cancel the query if it would use too much of | |
# your quota, with the limit set to 1 GB) | |
safe_config = bigquery.QueryJobConfig(maximum_bytes_billed=1e9) | |
query_job = client.query(query_popular, job_config=safe_config) | |
# API request - run the query, and convert the results to a pandas DataFrame | |
popular_comments = query_job.to_dataframe() | |
# Print the first five rows of the DataFrame | |
popular_comments.head() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment