Run a query with pandas-gbq

Use the pandas-gbq package to run a simple query.

Code sample

Python

Before trying this sample, follow the Python setup instructions in the BigQuery quickstart using client libraries . For more information, see the BigQuery Python API reference documentation .

To authenticate to BigQuery, set up Application Default Credentials. For more information, see Set up authentication for client libraries .

  import 
  
 pandas_gbq 
 # TODO: Set project_id to your Google Cloud Platform project ID. 
 # project_id = "my-project" 
 sql 
 = 
 """ 
 SELECT country_name, alpha_2_code 
 FROM `bigquery-public-data.utility_us.country_code_iso` 
 WHERE alpha_2_code LIKE 'A%' 
 """ 
 df 
 = 
 pandas_gbq 
 . 
 read_gbq 
 ( 
 sql 
 , 
 project_id 
 = 
 project_id 
 ) 
 

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser .

Create a Mobile Website
View Site in Mobile | Classic
Share by: