以圖表呈現查詢結果

透過這份快速入門導覽課程,在 BigQuery 筆記本中執行 SQL 並以視覺化方式呈現結果:

  • 使用 bigquery-public-data.ml_datasets.penguins 公開資料集執行查詢。
  • 使用 SQL 儲存格疊代查詢結果。
  • 使用視覺化儲存格,顯示每個物種的雌性企鵝平均喙長和喙深。

事前準備

  1. 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.
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  4. Verify that billing is enabled for your Google Cloud project.

  5. 確認已啟用 BigQuery API。

    啟用 API

    如果您建立新專案,系統會自動啟用 BigQuery API。

  6. 所需權限

    如要建立及執行 Notebook,您需要下列 Identity and Access Management (IAM) 角色:

    建立筆記本

    按照「從 BigQuery 編輯器建立筆記本」一文中的操作說明,建立新的筆記本。

    執行查詢

    如要在筆記本中執行 SQL 查詢,請按照下列步驟操作:

    1. 如要在筆記本中建立新的 SQL 儲存格,請按一下「SQL」

    2. 輸入下列查詢:

      SELECT * FROM `bigquery-public-data.ml_datasets.penguins`;
      
    3. 按一下 「Run cell」(執行儲存格)

      查詢結果會自動儲存到名為 df 的 DataFrame 中。

    4. 建立另一個 SQL 儲存格,並將標題變更為 female_penguins

    5. 輸入下列查詢,參照您剛建立的 DataFrame,並篩選結果,只納入雌性企鵝:

      SELECT * FROM {df} WHERE sex = 'FEMALE';
      
    6. 按一下 「Run cell」(執行儲存格)

      查詢結果會自動儲存到名為 female_penguins 的 DataFrame 中。

    以視覺化方式呈現結果

    1. 如要在筆記本中建立新的圖表儲存格,請按一下「圖表」

    2. 按一下「選擇資料框架」,然後選取 female_penguins

      系統隨即會顯示圖表介面。

    3. 按一下「散布圖」開啟圖表選單,然後選取 「直條圖」

    4. 在「指標」部分,確認顯示 culmen_length_mmculmen_depth_mm。如果缺少指標,請按一下「新增指標」,然後選取所需指標。如要移除指標,請將指標懸停在指標名稱上,然後按一下「關閉」

    5. 針對每個指標,按一下「編輯」。 在「匯總」部分,選取「平均值」

    顯示視覺化資料的長條圖

    清除所用資源

    如要避免付費,最簡單的方法就是刪除您為了本教學課程所建立的專案。

    如要刪除專案:

    1. In the Google Cloud console, go to the Manage resources page.

      Go to Manage resources

    2. In the project list, select the project that you want to delete, and then click Delete.
    3. In the dialog, type the project ID, and then click Shut down to delete the project.

    後續步驟