我正在尝试使用 BigQuery API 将 CSV 数据从云存储桶加载到 BigQuery 表 我的代码是:
def load_data_from_gcs(dataset_name, table_name, source):
bigquery_client = bigquery.Client()
dataset = bigquery_client.dataset(dataset_name)
table = dataset.table(table_name)
job_name = str(uuid.uuid4())
job = bigquery_client.load_table_from_storage(
job_name, table, source)
job.sourceFormat = 'CSV'
job.fieldDelimiter = ','
job.skipLeadingRows = 2
job.begin()
job.result() # Wait for job to complete
print('Loaded {} rows into {}:{}.'.format(
job.output_rows, dataset_name, table_name))
wait_for_job(job)
它给我错误:
400 CSV table encountered too many errors, giving up. Rows: 1; errors: 1.
此错误是因为,我的 csv 文件包含前两行作为标题信息,不应加载。我给了 job.skipLeadingRows = 2 但它没有跳过前两行。 是否有任何其他语法来设置跳过行?
请帮忙解决这个问题。
最佳答案
你拼错了(使用驼峰式而不是下划线)。它是 skip_leading_rows
,而不是 skipLeadingRows
。 field_delimiter
和 source_format
相同。
查看 Python 源代码 here .
关于google-bigquery - 如何跳过 BIGQUERY 加载 API 中的 csv 文件行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46262244/