Checkpoints
Create a new Cloud Storage bucket
/ 30
Copy data files to the storage bucket
/ 40
Loading Data into Google BigQuery
/ 30
Ingesting Data Into The Cloud
GSP194
Overview
In this lab you use a bash script to download selected data from a large public data set available on the internet. This data, made available on the US Bureau of Transport Statistics (BTS) website, provides historic information about internal flights in the United States.
The techniques used to ingest this data from the website into the cloud can be applied to other data sets that provide comprehensive real world data but must be parsed and cleaned before to be usefull.
Objectives
-
Retrieve initial data from the BTS website
-
Store the data in Cloud Storage
-
Load data into Google BigQuery
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud Console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Console. The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.
-
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Cloud Console opens in this tab.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
- Click Activate Cloud Shell
at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. The output contains a line that declares the PROJECT_ID for this session:
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
-
(Optional) You can list the active account name with this command:
-
Click Authorize.
-
Your output should now look like this:
Output:
-
(Optional) You can list the project ID with this command:
Output:
Example output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Prepare your environment
This lab uses a set of code samples and scripts developed for Data Science on Google Cloud from O'Reilly Media, Inc. You clone the sample repository used in Chapter 2 from Github to Cloud Shell and then carry out the lab tasks from there.
Clone the Data Science on Google Cloud repository
-
In Cloud Shell enter the following commands to clone the repository:
-
Change to the repository directory:
-
Make a directory to store working data and change into that directory:
Task 2. Retrieve data from a website
Fetch a sample data file using curl
You will use curl
to fetch the monthly CSV files that contain the raw data that will be used to build your complete data set. The data set is called the On-Time performance data. You can download a pre-configured data file for each month in any given year from the Bureau of Transportation Statistic.
-
For example, use the following
curl
command to fetch the data from January 2015:
-
Explore the downloaded data file to see what it looks like:
You'll see something similar to the following:
Although this file doesn't include header information and appears to contain data that's not needed, it demonstrates one way to acquire a starting data set.
Download custom data from a storage bucket
For this lab, snapshots of custom BTS data have been organized and saved in a public storage bucket. Download it from the data-science-on-gcp
public storage bucket. A script is provided in the repo to help achieve this.
-
In Cloud Shell, examine the
ingest_from_crsbucket.sh
script:
Output:
This script copies the monthly BTS data from year 2015 to your destination bucket.
-
To run the script, create a single-region bucket:
-
Run the download script using your bucket name as the argument:
Test completed task
Click Check my progress to verify your performed task. If you have completed the task successfully you will granted with an assessment score.
- In the Cloud Console tab, open Cloud Storage > Buckets.
There should be only one bucket with a name based on the lab project ID appended with -ml
, for example qwiklabs-gcp-04-495910fcff5c-ml
.
-
Click the storage bucket to open it.
-
Open the
flights
andraw
folders.
You will see that the processed .csv
texts have been copied to the storage bucket.
Task 3. Load data into Google BigQuery
For larger files, it's better to use gsutil
to ingest the files into Cloud Storage because gsutil
takes advantage of multithreaded, resumable uploads and is better suited to the public internet.
This is what you did in the previous section when you used gsutil
to copy the extracted flights CSV files to Cloud Storage.
-
Return to Cloud Shell to load the CSV files into BigQuery.
-
In Cloud Shell, examine the
bqload.sh
script:
Output:
This script loads the data from the Cloud Storage bucket to BigQuery.
-
Run the script using your bucket name as argument:
At this point, the CSV files are in Cloud Storage and the raw data in BigQuery.
Task 4. Test your understanding
Below are multiple-choice questions to reinforce your understanding of this lab's concepts. Answer them to the best of your abilities.
Summary
This lab has demonstrated how to:
-
Fetch raw data from a website in CSV format and perform some basic text actions to tidy it up.
-
Copy the data to a Cloud Storage bucket.
-
Load the data from a Cloud Storage bucket to BiqQuery where it can be reused easily.
Congratulations!
You now know how to copy a large text data set from a website and store it in a cloud storage bucket.
Finish your quest
This self-paced lab is part of the Data Science on Google Cloud quest. A quest is a series of related labs that form a learning path. Completing this quest earns you a badge to recognize your achievement. You can make your badge or badges public and link to them in your online resume or social media account. Enroll in this quest and get immediate completion credit.Refer to the Google Cloud Skills Boost catalog for all available quests.
Take your next lab
Continue your quest with Loading Data into Google Cloud SQL, or check out these suggestions:
Next steps / learn more
Here are some follow-up steps:
- Data Science on the Google Cloud Platform, 2nd Edition: O'Reilly Media, Inc..
- Airline Service Quality Performance (On-Time performance data) can be downloaded from Bureau of Transport Statistics.
Google Cloud training and certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated November 15, 2022
Lab Last Tested November 15, 2022
Copyright 2023 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.