Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions samples/snippets/pandas_methods_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ def test_bigquery_dataframes_pandas_methods():
bq_df = bpd.read_gbq(query_or_table)

# Inspect one of the columns (or series) of the DataFrame:
bq_df["body_mass_g"].head(10)
bq_df["body_mass_g"]

# Compute the mean of this series:
average_body_mass = bq_df["body_mass_g"].mean()
print(f"average_body_mass: {average_body_mass}")

# Calculate the mean body_mass_g by species using the groupby operation:
bq_df["body_mass_g"].groupby(by=bq_df["species"]).mean().head()
# Find the heaviest species using the groupby operation to calculate the
# mean body_mass_g:
(
bq_df["body_mass_g"]
.groupby(by=bq_df["species"])
.mean()
.sort_values(ascending=False)
.head(10)
)
# [END bigquery_dataframes_pandas_methods]
assert average_body_mass is not None