1414
1515
1616def run_quickstart (project_id : str ) -> None :
17- import bigframes
18-
19- session_options = bigframes .BigQueryOptions ()
20- session = bigframes .connect (session_options )
21-
2217 your_gcp_project_id = project_id
23- query_or_table = "bigquery-public-data.ml_datasets.penguins"
24- df_session = session .read_gbq (query_or_table )
25- average_body_mass = df_session ["body_mass_g" ].mean ()
26- print (f"average_body_mass (df_session): { average_body_mass } " )
2718
2819 # [START bigquery_bigframes_quickstart]
2920 import bigframes .pandas as bpd
@@ -33,10 +24,20 @@ def run_quickstart(project_id: str) -> None:
3324 # On BigQuery Studio, the project ID is automatically detected.
3425 bpd .options .bigquery .project = your_gcp_project_id
3526
27+ # Use "partial" ordering mode to generate more efficient queries, but the
28+ # order of the rows in DataFrames may not be deterministic if you have not
29+ # explictly sorted it. Some operations that depend on the order, such as
30+ # head() will not function until you explictly order the DataFrame. Set the
31+ # ordering mode to "strict" (default) for more pandas compatibility.
32+ bpd .options .bigquery .ordering_mode = "partial"
33+
3634 # Create a DataFrame from a BigQuery table
3735 query_or_table = "bigquery-public-data.ml_datasets.penguins"
3836 df = bpd .read_gbq (query_or_table )
3937
38+ # Efficiently preview the results using the .peek() method.
39+ df .peek ()
40+
4041 # Use the DataFrame just as you would a pandas DataFrame, but calculations
4142 # happen in the BigQuery query engine instead of the local system.
4243 average_body_mass = df ["body_mass_g" ].mean ()
0 commit comments