查詢公開資料集並將結果視覺化
瞭解如何在 BigQuery 中查詢公開資料集,並將結果視覺化。
如要直接在 Google Cloud 控制台按照逐步指南操作,請按一下「Guide me」(逐步引導):
事前準備
- 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.
-
Make sure that you have the following role or roles on the project: BigQuery Job User, Service Usage Admin
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
前往 IAM - 選取專案。
- 按一下 「授予存取權」。
-
在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that you have the following role or roles on the project: BigQuery Job User, Service Usage Admin
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
前往 IAM - 選取專案。
- 按一下 「授予存取權」。
-
在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
-
-
Verify that billing is enabled for your Google Cloud project.
確認已啟用 BigQuery API。
如果您建立新專案,系統會自動啟用 BigQuery API。
前往 Google Cloud 控制台的「BigQuery」頁面。
在 BigQuery Studio 的「Explorer」窗格中,按一下「新增資料」
。在「新增資料」對話方塊的「依條件篩選」窗格中,按一下
「公開資料集」。
在「Marketplace」頁面的「Search Marketplace」欄位中輸入
NYC Citi Bike Trips
,縮小搜尋範圍。在搜尋結果中,按一下「NYC Citi Bike Trips」。
在「產品詳細資料」頁面中,按一下「查看資料集」。您可以在「詳細資料」分頁中查看資料集相關資訊。
在 Google Cloud 控制台開啟「BigQuery」BigQuery頁面。
按一下
「SQL query」(SQL 查詢) 。在
查詢編輯器 中輸入以下查詢:SELECT start_station_name, start_station_latitude, start_station_longitude, ST_GEOGPOINT(start_station_longitude, start_station_latitude) AS geo_location, COUNT(*) AS num_trips FROM `bigquery-public-data.new_york.citibike_trips` GROUP BY 1, 2, 3 ORDER BY num_trips DESC LIMIT 100;
如果查詢有效,系統就會顯示勾號和查詢處理的資料量。如果查詢無效,則會顯示驚嘆號和錯誤訊息。
點選
「Run」(執行) ,「Query results」(查詢結果)部分會列出最熱門的電台。 選用步驟:如要查看工作持續時間和查詢工作處理的資料量,請點選「Query results」(查詢結果) 專區中的「Job information」(工作資訊) 分頁標籤。
切換至「Visualization」
分頁。這個分頁會生成地圖,方便您快速查看結果。 在「視覺化設定」面板中:
- 確認「圖表類型」已設為「地圖」。
- 確認「Geography column」(地理位置資料欄) 已設為
geo_location
。 - 在「資料欄」部分,選擇
num_trips
。 - 使用「 放大」選項,顯示曼哈頓地圖。
- 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 沙箱。
- 瞭解如何在 BigQuery 中建立資料集、載入資料及查詢資料表。
如果在本教學課程中使用的 Google Cloud 專案未啟用計費功能,您需要在 BigQuery 沙箱中查詢公開資料。BigQuery 沙箱可讓您學習 BigQuery,但可免費使用的 BigQuery 功能有限。
查看公開資料集
根據預設,BigQuery 公開資料集會直接顯示在名為 bigquery-public-data
的專案中。在本教學課程中,您將查詢紐約市 Citi Bike 行程資料集。Citi Bike 是大型自行車共享計畫,在曼哈頓、布魯克林、皇后區和澤西市設有 10,000 輛自行車及 600 個站點。這個資料集包含 Citi Bike 自 2013 年 9 月推出以來的行程。
查詢公開資料集
在下列步驟中,您會查詢 citibike_trips
資料表,找出 NYC Citi Bike 行程公開資料集中最熱門的 100 個 Citi Bike 租借站。這項查詢會擷取車站名稱和位置,以及從該車站出發的行程數量。
這項查詢會使用 ST_GEOGPOINT 函式,根據每個車站的經緯度參數建立點,並在 GEOGRAPHY
欄中傳回該點。GEOGRAPHY
欄用於在整合式地理資料檢視器中產生熱視圖。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
刪除專案
如果您使用 BigQuery 沙箱查詢公開資料集,則專案不會啟用帳單功能,因此您不需要刪除專案。
如要避免付費,最簡單的方法就是刪除您為了本教學課程所建立的專案。
如要刪除專案: