如何将包含列表的熊猫数据框上传到Google BigQuery数组和结构格式?

我想使用熊猫将数据框推入具有数组和结构的BigQuery表中

Bigquery表如下所示: col_a(int),col_b(字符串),col_c.A(具有数组子类型0的结构),col_c.B(具有int子类型的结构)

我有一个看起来像这样的数据框:

col_a(类型为int),col_b(字符串),col_c(对象列表),col_d(int)。

有没有一种方法可以将带有结构和数组的熊猫数据帧上传到bigquery表?

a16592664 回答:如何将包含列表的熊猫数据框上传到Google BigQuery数组和结构格式?

是的,你可以做到

import google.cloud
from google.cloud import bigquery


def save_df_to_bq(args,dataframe,csv_name):



print("Length of the incoming dataframe :-->",len(dataframe))

print(dataframe.iloc[[0]])

client = bigquery.Client()

dataset_ref = client.dataset(dataset_id,project_id)

 schema = [
     bigquery.SchemaField('col_a ','dttype'),bigquery.SchemaField('col_b ',bigquery.SchemaField('col_c ',]      

acc_table_id = str(random.randint(100000,100000*1000000))
# table_ref = dataset_ref.table(acc_table_id)
# table = bigquery.Table(table_ref,schema=schema)
# table = client.create_table(table)  # API request
# print("Table created..")

# acc_table_id = str(random.randint(100000,100000*1000000))
acc_table_ref = client.dataset(dataset_id,project_id).table(acc_table_id)
job = client.load_table_from_dataframe(dataframe,acc_table_ref,location="US")
job.result()
本文链接:https://www.f2er.com/3150311.html

大家都在问