Skip to content

Instantly share code, notes, and snippets.

@guerbai
Created June 2, 2019 05:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guerbai/7df3aab9c9d0c66c32eb59beb530c84b to your computer and use it in GitHub Desktop.
Save guerbai/7df3aab9c9d0c66c32eb59beb530c84b to your computer and use it in GitHub Desktop.
bigquery safequery #BigQuery
# 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