Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

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)[source]#

Write a DataFrame to a Google BigQuery table.

Deprecated since version 2.2.0:Please usepandas_gbq.to_gbq instead.

This function requires thepandas-gbq package.

See theHow to authenticate with Google BigQueryguide for authentication instructions.

Parameters:
destination_tablestr

Name of table to be written, in the formdataset.tablename.

project_idstr, optional

Google BigQuery Account project ID. Optional when available fromthe environment.

chunksizeint, optional

Number of rows to be inserted in each chunk from the dataframe.Set toNone to load the whole dataframe at once.

reauthbool, default False

Force Google BigQuery to re-authenticate the user. This is usefulif multiple accounts are used.

if_existsstr, default ‘fail’

Behavior when the destination table exists. Value can be one of:

'fail'

If table exists raise pandas_gbq.gbq.TableCreationError.

'replace'

If table exists, drop it, recreate it, and insert data.

'append'

If table exists, insert data. Create if does not exist.

auth_local_webserverbool, default True

Use thelocal webserver flow instead of theconsole flowwhen getting user credentials.

New in version 0.2.0 of pandas-gbq.

Changed in version 1.5.0:Default value is changed toTrue. Google has deprecated theauth_local_webserver=False“out of band” (copy-paste)flow.

table_schemalist of dicts, optional

List of BigQuery table fields to which according DataFramecolumns conform to, e.g.[{'name':'col1','type':'STRING'},...]. If schema is not provided, it will begenerated according to dtypes of DataFrame columns. SeeBigQuery API documentation on available names of a field.

New in version 0.3.1 of pandas-gbq.

locationstr, optional

Location where the load job should run. See theBigQuery locationsdocumentation for alist of available locations. The location must match that of thetarget dataset.

New in version 0.5.0 of pandas-gbq.

progress_barbool, default True

Use the librarytqdm to show the progress bar for the upload,chunk by chunk.

New in version 0.5.0 of pandas-gbq.

credentialsgoogle.auth.credentials.Credentials, optional

Credentials for accessing Google APIs. Use this parameter tooverride default credentials, such as to use Compute Enginegoogle.auth.compute_engine.Credentials or ServiceAccountgoogle.oauth2.service_account.Credentialsdirectly.

New in version 0.8.0 of pandas-gbq.

See also

pandas_gbq.to_gbq

This function in the pandas-gbq library.

read_gbq

Read a DataFrame from Google BigQuery.

Examples

Example taken fromGoogle BigQuery documentation

>>>project_id="my-project">>>table_id='my_dataset.my_table'>>>df=pd.DataFrame({..."my_string":["a","b","c"],..."my_int64":[1,2,3],..."my_float64":[4.0,5.0,6.0],..."my_bool1":[True,False,True],..."my_bool2":[False,True,False],..."my_dates":pd.date_range("now",periods=3),...}...)
>>>df.to_gbq(table_id,project_id=project_id)

[8]ページ先頭

©2009-2025 Movatter.jp