python - 将数据帧写回 BQ 表
问题描述
job_config = bigquery.LoadJobConfig()
# job_config.autodetect = True
# job_config.source_format = bigquery.SourceFormat.NEWLINE_DELIMITED_JSON
job_config = bigquery.LoadJobConfig(schema=[
bigquery.SchemaField("Weekend", "INT64")
])
job_config.write_disposition = "WRITE_TRUNCATE"
job = client.load_table_from_dataframe(
full_df_at, table_id, job_config=job_config
)
# Wait for the load job to complete.
job.result()
print('A table {} is created'.format(table_id))
此代码导致以下错误。
TypeError Traceback (most recent call last)
<ipython-input-39-c4a9bfab1edc> in <module>
5
6 job_config = bigquery.LoadJobConfig(schema=[
----> 7 bigquery.SchemaField("Weekend", "INT64")
8
9 ])
TypeError: __init__() got an unexpected keyword argument 'schema'
我该如何解决?这段代码运行良好。这是因为 Pandas 升级的变化吗?如何使此代码工作?
解决方案
您可以尝试:
job_config = bigquery.LoadJobConfig()
# job_config.autodetect = True
# job_config.source_format = bigquery.SourceFormat.NEWLINE_DELIMITED_JSON
job_config.schema = [
bigquery.SchemaField("Weekend", "INT64")
]
job_config.write_disposition = "WRITE_TRUNCATE"
job = client.load_table_from_dataframe(
full_df_at, table_id, job_config=job_config
)
# Wait for the load job to complete.
job.result()
print('A table {} is created'.format(table_id))
您可以查看适用于 Google BigQuery 的 Python 客户端,您可以在其中找到有关如何使用 LoadJobConfig 的示例。
推荐阅读
- c - 给出奇怪输出的 C 字符串
- r - 当我尝试使用 dplyr 按组求和时,为什么 dplyr 会忽略我的组?
- python - 为什么使用 pyinstaller 创建的 exe 文件在写入文件时存在问题?
- python - 使用下拉列表和回调更新 Bokeh 上的交互式图表
- javascript - 如何找到最小/最大日期javascript
- android - Android Studio - 如何在 Java/Kotlin 模块中指定“-jvm-target”选项?
- java - 我想在用户键入退出时将用户输入并将其存储在一个数组中,它应该打印用户键入的名称,升序..有什么提示吗?
- mysql - 批处理命令 FOR 循环加载 MySQL 数据 - (此时是意外的)
- javascript - Ag-grid 分组:避免在编辑后更改组的显示顺序
- visual-studio - MSBuild 路径相关问题