@@ -342,6 +342,51 @@ def read_gbq_query(
|
342 | 342 | ``row_number() over ()`` if there is no natural unique index or you
|
343 | 343 | want to preserve ordering.
|
344 | 344 |
|
| 345 | +**Examples:** |
| 346 | +
|
| 347 | +>>> import bigframes.pandas as bpd |
| 348 | +>>> bpd.options.display.progress_bar = None |
| 349 | +
|
| 350 | +Simple query input: |
| 351 | +
|
| 352 | +>>> df = bpd.read_gbq_query(''' |
| 353 | +... SELECT |
| 354 | +... pitcherFirstName, |
| 355 | +... pitcherLastName, |
| 356 | +... pitchSpeed, |
| 357 | +... FROM `bigquery-public-data.baseball.games_wide` |
| 358 | +... ''') |
| 359 | +>>> df.head(2) |
| 360 | +pitcherFirstName pitcherLastName pitchSpeed |
| 361 | +0 0 |
| 362 | +1 0 |
| 363 | +<BLANKLINE> |
| 364 | +[2 rows x 3 columns] |
| 365 | +
|
| 366 | +Preserve ordering in a query input. |
| 367 | +
|
| 368 | +>>> df = bpd.read_gbq_query(''' |
| 369 | +... SELECT |
| 370 | +... -- Instead of an ORDER BY clause on the query, use |
| 371 | +... -- ROW_NUMBER() to create an ordered DataFrame. |
| 372 | +... ROW_NUMBER() OVER (ORDER BY AVG(pitchSpeed) DESC) |
| 373 | +... AS rowindex, |
| 374 | +... |
| 375 | +... pitcherFirstName, |
| 376 | +... pitcherLastName, |
| 377 | +... AVG(pitchSpeed) AS averagePitchSpeed |
| 378 | +... FROM `bigquery-public-data.baseball.games_wide` |
| 379 | +... WHERE year = 2016 |
| 380 | +... GROUP BY pitcherFirstName, pitcherLastName |
| 381 | +... ''', index_col="rowindex") |
| 382 | +>>> df.head(2) |
| 383 | +pitcherFirstName pitcherLastName averagePitchSpeed |
| 384 | +rowindex |
| 385 | +1 Albertin Chapman 96.514113 |
| 386 | +2 Zachary Britton 94.591039 |
| 387 | +<BLANKLINE> |
| 388 | +[2 rows x 3 columns] |
| 389 | +
|
345 | 390 | See also: :meth:`Session.read_gbq`.
|
346 | 391 | """
|
347 | 392 | # NOTE: This method doesn't (yet) exist in pandas or pandas-gbq, so
|
@@ -405,6 +450,25 @@ def read_gbq_table(
|
405 | 450 | ) -> dataframe.DataFrame:
|
406 | 451 | """Turn a BigQuery table into a DataFrame.
|
407 | 452 |
|
| 453 | +**Examples:** |
| 454 | +
|
| 455 | +>>> import bigframes.pandas as bpd |
| 456 | +>>> bpd.options.display.progress_bar = None |
| 457 | +
|
| 458 | +Read a whole table, with arbitrary ordering or ordering corresponding to the primary key(s). |
| 459 | +
|
| 460 | +>>> df = bpd.read_gbq_table("bigquery-public-data.ml_datasets.penguins") |
| 461 | +>>> df.head(2) |
| 462 | +species island culmen_length_mm \\ |
| 463 | +0 Adelie Penguin (Pygoscelis adeliae) Dream 36.6 |
| 464 | +1 Adelie Penguin (Pygoscelis adeliae) Dream 39.8 |
| 465 | +<BLANKLINE> |
| 466 | +culmen_depth_mm flipper_length_mm body_mass_g sex |
| 467 | +0 18.4 184.0 3475.0 FEMALE |
| 468 | +1 19.1 184.0 4650.0 MALE |
| 469 | +<BLANKLINE> |
| 470 | +[2 rows x 7 columns] |
| 471 | +
|
408 | 472 | See also: :meth:`Session.read_gbq`.
|
409 | 473 | """
|
410 | 474 | # NOTE: This method doesn't (yet) exist in pandas or pandas-gbq, so
|
@@ -792,6 +856,16 @@ def _read_ibis(
|
792 | 856 | def read_gbq_model(self, model_name: str):
|
793 | 857 | """Loads a BigQuery ML model from BigQuery.
|
794 | 858 |
|
| 859 | +**Examples:** |
| 860 | +
|
| 861 | +>>> import bigframes.pandas as bpd |
| 862 | +>>> bpd.options.display.progress_bar = None |
| 863 | +
|
| 864 | +Read an existing BigQuery ML model. |
| 865 | +
|
| 866 | +>>> model_name = "bigframes-dev.bqml_tutorial.penguins_model" |
| 867 | +>>> model = bpd.read_gbq_model(model_name) |
| 868 | +
|
795 | 869 | Args:
|
796 | 870 | model_name (str):
|
797 | 871 | the model's name in BigQuery in the format
|
@@ -815,6 +889,22 @@ def read_pandas(self, pandas_dataframe: pandas.DataFrame) -> dataframe.DataFrame
|
815 | 889 | The pandas DataFrame will be persisted as a temporary BigQuery table, which can be
|
816 | 890 | automatically recycled after the Session is closed.
|
817 | 891 |
|
| 892 | +**Examples:** |
| 893 | +
|
| 894 | +>>> import bigframes.pandas as bpd |
| 895 | +>>> import pandas as pd |
| 896 | +>>> bpd.options.display.progress_bar = None |
| 897 | +
|
| 898 | +>>> d = {'col1': [1, 2], 'col2': [3, 4]} |
| 899 | +>>> pandas_df = pd.DataFrame(data=d) |
| 900 | +>>> df = bpd.read_pandas(pandas_df) |
| 901 | +>>> df |
| 902 | +col1 col2 |
| 903 | +0 1 3 |
| 904 | +1 2 4 |
| 905 | +<BLANKLINE> |
| 906 | +[2 rows x 2 columns] |
| 907 | +
|
818 | 908 | Args:
|
819 | 909 | pandas_dataframe (pandas.DataFrame):
|
820 | 910 | a pandas DataFrame object to be loaded.
|
@@ -1365,6 +1455,16 @@ def read_gbq_function(
|
1365 | 1455 | The return type of the function must be explicitly specified in the
|
1366 | 1456 | function's original definition even if not otherwise required.
|
1367 | 1457 |
|
| 1458 | +**Examples:** |
| 1459 | +
|
| 1460 | +>>> import bigframes.pandas as bpd |
| 1461 | +>>> bpd.options.display.progress_bar = None |
| 1462 | +
|
| 1463 | +>>> function_name = "bqutil.fn.cw_lower_case_ascii_only" |
| 1464 | +>>> func = bpd.read_gbq_function(function_name=function_name) |
| 1465 | +>>> func.bigframes_remote_function |
| 1466 | +'bqutil.fn.cw_lower_case_ascii_only' |
| 1467 | +
|
1368 | 1468 | Args:
|
1369 | 1469 | function_name (str):
|
1370 | 1470 | the function's name in BigQuery in the format
|
|
0 commit comments