gpt4 book ai didi

python - 从bigquery加载大数据到python

转载 作者:行者123 更新时间:2023-12-01 02:41:17 27 4
gpt4 key购买 nike

from google.cloud import bigquery as bq
import google_auth_oauthlib.flow

query = '''select ... from ...'''

bigquery_client = bq.Client()
table = bq.query.QueryResults(query=query,client=bigquery_client)
table.use_legacy_sql = False
table.run()

# transfer bigquery data to pandas dataframe
columns=[field.name for field in table.schema]
rows = table.fetch_data()
data = []
for row in rows:
data.append(row)

df = pd.DataFrame(data=data[0],columns=columns)

我想将超过 1000 万行加载到 python 中,几周前它运行良好,但现在它只返回 100,000 行。有人知道可靠的方法吗?

最佳答案

我刚刚在这里测试了这段代码,可以带来 300 万行,并且没有应用上限:

import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'path/to/key.json'

from google.cloud.bigquery import Client

bc = Client()
query = 'your query'

job = bc.run_sync_query(query)
job.use_legacy_sql = False
job.run()

data = list(job.fetch_data())

这对你有用吗?

关于python - 从bigquery加载大数据到python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45697327/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com