Answers for "bigquery python"

0

python bigquery

from google.cloud import bigquery

# Construct a BigQuery client object.
client = bigquery.Client()

query = """
    SELECT name, SUM(number) as total_people
    FROM `bigquery-public-data.usa_names.usa_1910_2013`
    WHERE state = 'TX'
    GROUP BY name, state
    ORDER BY total_people DESC
    LIMIT 20
"""
query_job = client.query(query)  # Make an API request.

print("The query data:")
for row in query_job:
    # Row values can be accessed by field name or index.
    print("name={}, count={}".format(row[0], row["total_people"]))
Posted by: Guest on July-31-2021
0

how to start the code in BigQuery for python

from google.cloud import bigquery

# Create a "Client" object
client = bigquery.Client()

# Construct a reference to the "hacker_news" dataset
dataset_ref = client.dataset("data_set_name", project="project_name")

# API request - fetch the dataset
dataset = client.get_dataset(dataset_ref)

# Construct a reference to the "a_table" table
table_ref = dataset_ref.table("a_table")

# API request - fetch the table
table = client.get_table(table_ref)

# Preview the first five lines of the "comments" table
client.list_rows(table, max_results=5).to_dataframe()
Posted by: Guest on October-25-2021

Python Answers by Framework

Browse Popular Code Answers by Language