@@ -316,36 +316,36 @@ def _parse_data(client, job, index_col=None, col_order=None):
316
316
return final_df
317
317
318
318
def to_gbq (dataframe , destination_table , schema = None , col_order = None , if_exists = 'fail' , ** kwargs ):
319
- """
320
- Write a DataFrame to a Google BigQuery table. If the table exists,
321
- the DataFrame will be appended. If not, a new table will be created,
322
- in which case the schema will have to be specified. By default,
319
+ """Write a DataFrame to a Google BigQuery table.
320
+
321
+ If the table exists, the DataFrame will be appended. If not, a new table
322
+ will be created, in which case the schema will have to be specified. By default,
323
323
rows will be written in the order they appear in the DataFrame, though
324
324
the user may specify an alternative order.
325
325
326
326
Parameters
327
- ---------------
328
- dataframe: DataFrame
327
+ ----------
328
+ dataframe : DataFrame
329
329
DataFrame to be written
330
- destination_table: string
330
+ destination_table : string
331
331
name of table to be written, in the form 'dataset.tablename'
332
332
schema : sequence (optional)
333
333
list of column types in order for data to be inserted, e.g. ['INTEGER', 'TIMESTAMP', 'BOOLEAN']
334
- col_order: sequence (optional)
334
+ col_order : sequence (optional)
335
335
order which columns are to be inserted, e.g. ['primary_key', 'birthday', 'username']
336
- if_exists: {'fail', 'replace', 'append'} (optional)
337
- fail: If table exists, do nothing.
338
- replace: If table exists, drop it, recreate it, and insert data.
339
- append: If table exists, insert data. Create if does not exist.
336
+ if_exists : {'fail', 'replace', 'append'} (optional)
337
+ - fail: If table exists, do nothing.
338
+ - replace: If table exists, drop it, recreate it, and insert data.
339
+ - append: If table exists, insert data. Create if does not exist.
340
340
kwargs are passed to the Client constructor
341
341
342
- Raises:
342
+ Raises
343
343
------
344
- SchemaMissing:
344
+ SchemaMissing :
345
345
Raised if the 'if_exists' parameter is set to 'replace', but no schema is specified
346
- TableExists:
346
+ TableExists :
347
347
Raised if the specified 'destination_table' exists but the 'if_exists' parameter is set to 'fail' (the default)
348
- InvalidSchema:
348
+ InvalidSchema :
349
349
Raised if the 'schema' parameter does not match the provided DataFrame
350
350
"""
351
351
@@ -416,35 +416,37 @@ def to_gbq(dataframe, destination_table, schema=None, col_order=None, if_exists=
416
416
job = client .Load (table_reference , csv_file .name , schema = schema , ** opts )
417
417
418
418
def read_gbq (query , project_id = None , destination_table = None , index_col = None , col_order = None , ** kwargs ):
419
- """
419
+ """Load data from Google BigQuery.
420
+
420
421
The main method a user calls to load data from Google BigQuery into a pandas DataFrame.
421
422
This is a simple wrapper for Google's bq.py and bigquery_client.py, which we use
422
423
to get the source data. Because of this, this script respects the user's bq settings
423
424
file, '~/.bigqueryrc', if it exists. Such a file can be generated using 'bq init'. Further,
424
- additional parameters for the query can be specified as either **kwds in the command,
425
+ additional parameters for the query can be specified as either `` **kwds`` in the command,
425
426
or using FLAGS provided in the 'gflags' module. Particular options can be found in
426
427
bigquery_client.py.
427
428
428
429
Parameters
429
430
----------
430
- query: str
431
+ query : str
431
432
SQL-Like Query to return data values
432
- project_id: str (optional)
433
+ project_id : str (optional)
433
434
Google BigQuery Account project ID. Optional, since it may be
434
435
located in ~/.bigqueryrc
435
- index_col: str (optional)
436
+ index_col : str (optional)
436
437
Name of result column to use for index in results DataFrame
437
- col_order: list(str) (optional)
438
+ col_order : list(str) (optional)
438
439
List of BigQuery column names in the desired order for results
439
440
DataFrame
440
- destination_table: string (optional)
441
+ destination_table : string (optional)
441
442
If provided, send the results to the given table.
442
- **kwargs: to be passed to bq.Client.Create(). Particularly: 'trace', 'sync',
443
- 'api', 'api_version'
443
+ **kwargs :
444
+ To be passed to bq.Client.Create(). Particularly: 'trace',
445
+ 'sync', 'api', 'api_version'
444
446
445
447
Returns
446
448
-------
447
- df: pandas DataFrame
449
+ df: DataFrame
448
450
DataFrame representing results of query
449
451
450
452
"""
0 commit comments