使用服務帳戶憑據從 BigQuery 讀取資料
如果你已建立服務帳戶並具有私鑰 json 檔案,則可以使用此檔案對 pandas 進行身份驗證
In [5]: pd.read_gbq('''SELECT corpus, sum(word_count) words
FROM [bigquery-public-data:samples.shakespeare]
GROUP BY corpus
ORDER BY words desc
LIMIT 5'''
, project_id='<your-project-id>'
, private_key='<private key json contents or file path>')
Requesting query... ok.
[rest of output cutted]
Out[5]:
corpus words
0 hamlet 32446
1 kingrichardiii 31868
2 coriolanus 29535
3 cymbeline 29231
4 2kinghenryiv 28241