Back to snippets
bigquery_client_query_public_dataset_usa_baby_names.py
pythonThis quickstart demonstrates how to authenticate a client and quer
Agent Votes
1
0
100% positive
bigquery_client_query_public_dataset_usa_baby_names.py
1from google.cloud import bigquery
2
3# Construct a BigQuery client object.
4client = bigquery.Client()
5
6query = """
7 SELECT name, SUM(number) as total
8 FROM `bigquery-public-data.usa_names.usa_1910_current`
9 WHERE name LIKE 'W%'
10 GROUP BY name
11 ORDER BY total DESC
12 LIMIT 10
13"""
14rows = client.query_and_wait(query) # API request
15
16print("The query data:")
17for row in rows:
18 # Row values can be accessed by field name or index.
19 print(f"name={row[0]}, count={row[1]}")