Let's use BigQuery's client library in Python to get data on BigQuery.
pip install --upgrade google-cloud-bigquery
To enable the client library, you need to create a service account and set up authentication. If not set, a DefaultCredentialsError will occur.
"IAM and management" → "Service account" → "Create service account"
After creating a service account with, the JSON file containing the key will be downloaded with "Create Key".
I have created the following dataset in BigQuery.
from google.cloud import bigquery
import os
#Describe the path of the downloaded json file
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = './*****.json'
client = bigquery.Client()
sql = "select *from dataset name.table name"
df = client.query(sql).to_dataframe()
project_id = 'Project ID'
df = client.query(sql, project=project_id).to_dataframe()
print(df.head())
I was able to get the data firmly.
https://cloud.google.com/bigquery/docs/reference/libraries?hl=ja
Recommended Posts