14
14
15
15
16
16
def run_quickstart (project_id : str ) -> None :
17
- import bigframes
18
-
19
- session_options = bigframes .BigQueryOptions ()
20
- session = bigframes .connect (session_options )
21
-
22
17
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 } " )
27
18
28
19
# [START bigquery_bigframes_quickstart]
29
20
import bigframes .pandas as bpd
@@ -33,10 +24,20 @@ def run_quickstart(project_id: str) -> None:
33
24
# On BigQuery Studio, the project ID is automatically detected.
34
25
bpd .options .bigquery .project = your_gcp_project_id
35
26
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
+
36
34
# Create a DataFrame from a BigQuery table
37
35
query_or_table = "bigquery-public-data.ml_datasets.penguins"
38
36
df = bpd .read_gbq (query_or_table )
39
37
38
+ # Efficiently preview the results using the .peek() method.
39
+ df .peek ()
40
+
40
41
# Use the DataFrame just as you would a pandas DataFrame, but calculations
41
42
# happen in the BigQuery query engine instead of the local system.
42
43
average_body_mass = df ["body_mass_g" ].mean ()
0 commit comments