pandas.DataFrame.to_gbq#

DataFrame.to_gbq(destination_table, project_id=None, chunksize=None, reauth=False, if_exists='fail', auth_local_webserver=True, table_schema=None, location=None, progress_bar=True, credentials=None)[源代码]#

向Google BigQuery表编写一个DataFrame。

此函数需要 pandas-gbq package

请参阅 How to authenticate with Google BigQuery 身份验证说明指南。

参数
destination_table应力

要写入的表格的名称,格式为 dataset.tablename

project_id字符串,可选

Google BigQuery帐户项目ID。在环境中可用时可选。

chunksize整型,可选

要从数据帧插入到每个区块中的行数。设为 None 一次加载整个数据帧。

reauth布尔值,默认为False

强制Google BigQuery重新验证用户身份。如果使用多个帐户,这将非常有用。

if_exists字符串,默认为‘FAIL’

目标表存在时的行为。值可以是以下值之一:

'fail'

如果表存在,则引发Pandas_gbq.gbq.TableCreationError。

'replace'

如果表存在,则删除它,重新创建它,然后插入数据。

'append'

如果表存在,则插入数据。Create If不存在。

auth_local_webserver布尔值,默认为True

使用 local webserver flow 而不是 console flow 在获取用户凭据时。

New in version 0.2.0 of pandas-gbq

在 1.5.0 版更改: 缺省值更改为 True 。谷歌已经弃用了 auth_local_webserver = False "out of band" (copy-paste) flow

table_schema词典列表,可选

符合DataFrame列的BigQuery表字段列表,例如 [{{'name': 'col1', 'type': 'STRING'}},...] 。如果不提供SCHEMA,则根据DataFrame列的数据类型生成。有关字段的可用名称,请参阅BigQuery API文档。

New in version 0.3.1 of pandas-gbq

location字符串,可选

加载作业应运行的位置。请参阅 BigQuery locations documentation 获取可用位置的列表。该位置必须与目标数据集的位置匹配。

New in version 0.5.0 of pandas-gbq

progress_bar布尔值,默认为True

使用库 tqdm 要显示上载的进度条,请逐块显示。

New in version 0.5.0 of pandas-gbq

credentialsGoogle.auth.redentials.Credentials,可选

访问Google API的凭据。使用此参数覆盖默认凭据,例如使用计算引擎 google.auth.compute_engine.Credentials 或服务帐户 google.oauth2.service_account.Credentials 直接去吧。

New in version 0.8.0 of pandas-gbq

参见

pandas_gbq.to_gbq

此函数在pandas-gbq库中。

read_gbq

阅读Google BigQuery上的DataFrame。