Skip to content

Commit 87f84c9

Browse files
authored
docs: use head() to get top n results, not to preview results (#190)
head() requires ordering. Just peeking at the whole DataFrame or Series is actually more efficient since it doesn't require ordering and still only downloads a fraction of the results. Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/python-bigquery-dataframes/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕
1 parent 7d2be00 commit 87f84c9

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

samples/snippets/pandas_methods_test.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,20 @@ def test_bigquery_dataframes_pandas_methods():
2222
bq_df = bpd.read_gbq(query_or_table)
2323

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

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

31-
# Calculate the mean body_mass_g by species using the groupby operation:
32-
bq_df["body_mass_g"].groupby(by=bq_df["species"]).mean().head()
31+
# Find the heaviest species using the groupby operation to calculate the
32+
# mean body_mass_g:
33+
(
34+
bq_df["body_mass_g"]
35+
.groupby(by=bq_df["species"])
36+
.mean()
37+
.sort_values(ascending=False)
38+
.head(10)
39+
)
3340
# [END bigquery_dataframes_pandas_methods]
3441
assert average_body_mass is not None

0 commit comments

Comments
 (0)