首页 > 解决方案 > 如何使用python自动更新谷歌大查询中的数据?

问题描述

我的阶段:

我是初学者。因此,当我想更新数据时,我删除了谷歌大查询中的表并再次运行 python 代码。现在我想自动更新数据。是否可以使用 python 做到这一点?

标签: pythongoogle-bigqueryscheduling

解决方案


我建议使用 Bigquery Python API。您可以使用pip install google-cloud-bigquery. 那么你也能

from google.cloud import bigquery

# Connect to Bigquery
client = bigquery.Client(project=your_project_id)

# Pull data to DF
df = client.query('select * from your_dataset.your_table').to_dataframe()

# Write table to Bigquery
job = client.load_table_from_dataframe(df, 'your_dataset.your_table')

# If you want to overwrite an existing table
job_config = bigquery.LoadJobConfig(
    write_disposition="WRITE_TRUNCATE",
)
job = client.load_table_from_dataframe(
     df, 'your_dataset.your_existing_table', job_config=job_config
)

推荐阅读