使用Python客户端将CSV追加到BigQuery表

使用Python客户端将CSV追加到BigQuery表,python,python-3.x,google-bigquery,python-bigquery,Python,Python 3.x,Google Bigquery,Python Bigquery,我每周都有一个相同格式的新CSV文件,我需要使用Python客户端将其附加到BigQuery表中。我使用第一个CSV成功地创建了表,但我不确定接下来如何附加CSV。我找到的唯一方法是google.cloud.bigquery.client.client.insert\u rows方法。请参阅api链接。这将需要我首先阅读CSV作为字典列表。有没有更好的方法将CSV中的数据附加到BigQuery表中?请参见下面的简单示例 # from google.cloud import bigquery #

我每周都有一个相同格式的新CSV文件,我需要使用Python客户端将其附加到BigQuery表中。我使用第一个CSV成功地创建了表,但我不确定接下来如何附加CSV。我找到的唯一方法是google.cloud.bigquery.client.client.insert\u rows方法。请参阅api链接。这将需要我首先阅读CSV作为字典列表。有没有更好的方法将CSV中的数据附加到BigQuery表中?

请参见下面的简单示例

# from google.cloud import bigquery
# client = bigquery.Client()
# table_ref = client.dataset('my_dataset').table('existing_table')

job_config = bigquery.LoadJobConfig()
job_config.write_disposition = bigquery.WriteDisposition.WRITE_APPEND
job_config.skip_leading_rows = 1

# The source format defaults to CSV, so the line below is optional.
job_config.source_format = bigquery.SourceFormat.CSV
uri = "gs://your_bucket/path/your_file.csv"
load_job = client.load_table_from_uri(
    uri, table_ref, job_config=job_config
)  # API request
print("Starting job {}".format(load_job.job_id))

load_job.result()  # Waits for table load to complete.
print("Job finished.")

destination_table = client.get_table(table_ref)
print("Loaded {} rows.".format(destination_table.num_rows))  
请参阅中的更多详细信息