gpt4 book ai didi

python - BigQuery,使用 python 客户端加载包含重复字段的数据帧

转载 作者:太空宇宙 更新时间:2023-11-03 20:18:47 24 4
gpt4 key购买 nike

我正在将 python 程序中的 pandas 数据帧加载到 bigquery 表中。

代码:

table_id = 'project.dataset.table'
job = client.load_table_from_dataframe(df, table_id)
job.result()

我的数据框包含几列,用于存储大型 float 组。

由于底层 pyarrow 库存在一些问题,使用 python 库中的 load_table_from_dataframe 方法加载重复字段似乎存在问题,如 here 所示。

解决这个问题的最佳方法是什么?

最佳答案

用解决方法回答我自己的问题。

  1. 我首先尝试使用 pandas_gbq.to_gbq() 但它的类型支持很差,所以不起作用。

  2. 工作解决方案涉及将数据帧转换为字典并将其流式传输到 bigquery

df_dict = df.to_dict(orient='records')

def insert_bq_row(rows):
global client
res = client.insert_rows(table, rows)
assert res == []

insert_bq_row(df_dict)

关于python - BigQuery,使用 python 客户端加载包含重复字段的数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58285558/

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