使用服务帐户凭据从 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