Home > other >  pandas array of integers to BigQuery using python
pandas array of integers to BigQuery using python

Time:07-08

I'm trying to load an array of integers from a pandas dataframe into BigQuery. The load works well, but the array is empty (looses all the integers inside)

enter image description here

What am I missing here? Any ideas/suggestions?

tableId = test-dev.xpto.array
df = pd.DataFrame()
    df['name'] = ['city']
    df['channels'] = [[1, 13, 36]]

schema = [
    bigquery.SchemaField("name", "STRING", mode="NULLABLE"),
    bigquery.SchemaField("channels", "INT64", mode="REPEATED")
]
job_config = bigquery.LoadJobConfig(
        schema=schema,
        create_disposition="CREATE_IF_NEEDED",
        write_disposition="WRITE_APPEND",
    )

job = client.load_table_from_dataframe(
            df, table_id, job_config=job_config
        )


CodePudding user response:

I've tried your code and it is working flawlessly. The only thing I've changed is the line tableId = test-dev.xpto.array to table_id = 'my-project.my_dataset.my_table' to match the argument in job.

enter image description here

  • Related