python - 如何使用python自动更新谷歌大查询中的数据?
问题描述
我的阶段:
- 使用python连接MySql数据库(IDE:Spyder)
- 拉取数据并转换数据框
- 使用 python 连接到 Google Big Query
- 将数据框写入 Google Big Query
我是初学者。因此,当我想更新数据时,我删除了谷歌大查询中的表并再次运行 python 代码。现在我想自动更新数据。是否可以使用 python 做到这一点?
解决方案
我建议使用 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
)
推荐阅读
- python - 类型错误:close() 缺少 1 个必需的位置参数:'self'
- neo4j - 在图形数据库中,您可以拥有多少个节点标签是否有限制?
- json - 如何读取嵌套的 json?
- google-bigquery - BigQuery 中的更新和内部联接语句问题
- laravel - 找不到类 'Yajra\DataTables\Services\DataTable'
- java - 这个符号在 IntelliJ 中是什么意思?Java 类名上的照明符号
- java - Observer / Observable to PropertyChangeListener
- android - Google Analytics: How to display the breakdown of an event parameter over custom period?
- mocking - 使用 pytest 进行模拟或猴子修补
- c# - Compiling SharpDX : xaudio2.h(65,68): Process error CX0001: cannot call operator __uuidof on a type with no GUID