可视化查询结果
在本快速入门中,您将学习如何在 BigQuery 笔记本中运行 SQL 并直观呈现结果:
- 使用
bigquery-public-data.ml_datasets.penguins
公共数据集运行查询。 - 使用 SQL 代码单元迭代查询结果。
- 使用可视化图表单元格显示每种企鹅的雌性企鹅平均喙长和喙深。
准备工作
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator
), which contains theresourcemanager.projects.create
permission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
验证已启用 BigQuery API。
如果您创建了一个新项目,则系统会自动启用 BigQuery API。
如需在笔记本中创建新的 SQL 代码单元,请点击
SQL。输入以下查询:
SELECT * FROM `bigquery-public-data.ml_datasets.penguins`;
点击
运行单元。查询结果会自动保存到名为
df
的 DataFrame 中。创建另一个 SQL 代码单元,并将标题更改为
female_penguins
。输入以下查询,该查询会引用您刚刚创建的 DataFrame,并过滤结果以仅包含雌性企鹅:
SELECT * FROM {df} WHERE sex = 'FEMALE';
点击
运行单元。查询结果会自动保存在名为
female_penguins
的 DataFrame 中。如需在笔记本中创建新的可视化图表单元,请点击
可视化图表。点击选择 DataFrame,然后选择
female_penguins
。系统随即会显示图表界面。
点击散点图打开图表菜单,然后选择
竖条图。在指标部分,检查是否显示
culmen_length_mm
和culmen_depth_mm
。如果缺少某个指标,请点击 添加指标,然后选择该指标。如需移除某个指标,请将指针悬停在该指标名称上,然后点击 关闭。针对每个指标,点击
修改。 对于聚合,请选择平均值。- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
- 详细了解 BigQuery DataFrames。
- 详细了解 Colab Enterprise 中的 SQL 代码单元。
- 详细了解 Colab Enterprise 中的可视化单元。
- 了解如何使用 BigQuery DataFrames 直观呈现图表。
- 了解如何使用 BigQuery DataFrames 笔记本。
所需权限
如需创建和运行笔记本,您需要以下 Identity and Access Management (IAM) 角色:
创建笔记本
按照通过 BigQuery 编辑器创建笔记本中的说明创建新的笔记本。
运行查询
如需在笔记本中运行 SQL 查询,请按以下步骤操作:
直观呈现结果
清理
为了避免产生费用,最简单的方法是删除您为本教程创建的项目。
要删除项目,请执行以下操作: