我是一个新手,我刚刚开始一个查询,在 bigquery 上有大约 100 万行,它有 25 列。行的类型是 RowIterator
我用 Python 编写了一个脚本来循环它们并处理数据。我用过:
client = bigquery.Client()
query_job = client.query(query)
rows = query_job.result() (~1 million records)
df = rows.to_dataframe() (*)
dict_rows = df.to_dict(orient="records")
for row in dict_rows:
# process data
(*) 大约需要 5-6 分钟。这对我来说不太好。
关于如何更快地处理它有什么建议吗?谢谢。
如果可以直接在迭代器中处理原始行,那么如何处理结果行是相关的,没有详细信息,不加载到数据帧并转换为字典是一个开始。
for row in query_job.result():
#Process Data
或者使用生成器理解或生成器函数。
gerator_comprehension_result = (#Process row for row in query_job.result())
def process_data(data):
for row in data:
#Process row
yield row_modified
generator_function_result = process_data(query_job.result())