Unit 5 Cloud Pipelines Notes
Reading Data from S3
For the first time, your Databricks notebook will look at actual data — loading a dataset, navigating its rows and columns, and confirming that what arrived is what you expected.
Learning Objectives
- Explain what “reading data” means in the context of a cloud data pipeline
- Understand how a dataset is structured as rows and columns — and what each represents
- Load a sample dataset into a Databricks notebook and display its contents
- Navigate to a specific row, a specific value, and count the total number of records in a dataset
- Explain why inspecting data before processing is a critical step in any real business pipeline
In previous units you set up storage (S3) and learned to run code (notebooks). This unit is the moment those two things connect — a notebook reaches into S3 and actually reads what is there.
Reading data means loading a file from storage into an active working environment where code can interact with it. Until a file is read, it is just bytes sitting in a folder. Once read, it becomes a structured dataset your notebook can count, navigate, inspect, and eventually clean.
Imagine your business receives a delivery of supplier invoices. They arrive in a sealed box (the S3 bucket). Reading the data is the moment you open the box, spread the invoices on the table, and start examining them — checking that every invoice is there, that the amounts look reasonable, and that nothing is obviously wrong before you begin entering them into the accounting system. You would never start processing invoices without checking them first. The same logic applies to every dataset that enters a pipeline.
Every dataset you will work with in this course — and in virtually any real pipeline — is organized as a grid of rows and columns. This is true whether the file is a CSV, an Excel sheet, or a database table. Understanding this structure is the foundation of all data work.
A school register lists every student in the class. Each row is one student. Each column is one piece of information about that student: their name, their ID number, their grade. To find a specific piece of information — say, the grade of the third student — you go to the third row and the grade column. That intersection is one value. Every dataset works exactly this way.
The sample dataset represents a simple sales report with three employees, their sales figures, and their regions. This is the data you will load, navigate, and inspect across five notebook cells.
In Python, items in a list are numbered starting from zero, not one. This trips up almost everyone the first time they see it — but there is a simple way to remember it.
In many countries, the ground floor of a building is called “Floor 0” — not Floor 1. The first floor above ground is Floor 1, the next is Floor 2. Python numbering works identically. The first item in a list is at position 0, the second is at position 1, the third is at position 2. Once you think of 0 as “the ground floor,” the pattern becomes completely natural.
Applied to the sales dataset: Alice is at index 0, Bob is at index 1, Charlie is at index 2. To get Bob’s sales figure, you go to row 1 (the second row) and then position 1 within that row (the second value — sales).
| Index | Row Contents | How to Access It |
|---|---|---|
| 0 | [“Alice”, 500, “West”] | data[0] — the whole first row |
| 1 | [“Bob”, 700, “East”] | data[1] — the whole second row |
| 2 | [“Charlie”, 450, “North”] | data[2] — the whole third row |
To access a single value within a row, you use two index numbers. data[1][1] means: go to row 1 (Bob), then go to position 1 within that row (sales amount) — which gives you 700.
Create a new notebook in Databricks named Unit5_Read_Data, set the language to Python, and attach it to your cluster. Run each cell below in order.
[“Alice”, 500, “West”],
[“Bob”, 700, “East”],
[“Charlie”, 450, “North”]
]
print(data)
The variable data holds a list of three rows. Each row is itself a list — a set of values enclosed in square brackets. The first value in each row is a name (text, in quotes), the second is a sales figure (a number, no quotes), and the third is a region (text, in quotes). When you print the whole variable, Python displays every row at once. In a real pipeline, instead of typing this data manually, a line of code would read it directly from your CSV file in S3 — the structure would look identical, but the values would come from the file. That connection is being built unit by unit.
data[0] retrieves the item at index position 0 — the first row. Remember: Python starts counting at zero, so position 0 is Alice’s row. This is the equivalent of opening a filing cabinet and pulling out the first folder. In pipeline validation, analysts commonly inspect the first few rows to confirm the data loaded correctly — checking that column values are in the right positions before running any processing logic on the full dataset.
Two index numbers are used here. The first [1] selects the second row in the dataset — Bob’s row (remember, index 1 is the second item). The second [1] selects the second value inside that row — the sales amount. The result is 700, which is Bob’s sales figure. Think of it like a grid reference on a map: the first number tells you which row, the second tells you which column. Together they pinpoint one exact value. In a real cleaning or calculation step, this is how the notebook reaches into the data to check or use a specific value.
len() is a built-in Python function that returns the number of items in a list. Here it counts the rows in the dataset and the result — 3 — confirms that all three records loaded correctly. This is one of the most common validation checks in a real pipeline. If a sales file is expected to contain 500 rows and len() returns 12, something went wrong — the file is incomplete, truncated, or the wrong file was uploaded entirely. Checking the row count immediately after loading is a fast, reliable way to catch these problems before any processing begins.
print(“Reading dataset from S3:”, file_name)
This cell simulates the log message a pipeline would produce when it begins reading a file from S3. In a production notebook, this line would appear at the top of the reading section — confirming which file is being loaded, from which path, at which point in the run. It is a checkpoint: anyone reading the logs later knows exactly which file was processed. The file name here is typed manually because you have not yet connected Databricks directly to your S3 bucket — that full connection is introduced in Unit 6 and expanded in Unit 9. Right now, the simulation builds the habit of logging clearly before any data is touched.
The cells in this unit feel simple — and they are. But the habits they build are exactly those used in production pipelines handling millions of records daily. Inspection is never skipped in professional data work because the consequences of processing bad data are far worse than the time spent checking it first.
Every check you run at the reading stage is a gate — something the data must pass through before processing is allowed to begin. In large organizations, these gates are documented, automated, and audited. They protect every downstream consumer of the data — the analyst, the dashboard, the report, the decision — from receiving information that was wrong from the moment it arrived.
Unit 6 is where the data stops being observed and starts being changed. You will apply cleaning rules — removing blank rows, fixing formatting, standardizing values — directly to the dataset you learned to load and navigate in this unit. Everything you practised here is the foundation that makes cleaning possible.
Knowledge Check
Five questions covering the key concepts from Unit 5. Select the best answer for each question.
1. In Python, if a list has three items, what index number refers to the first item?
2. What does data[1][1] return from the sales dataset in this unit?
3. What does len(data) measure in the context of the sales dataset?
4. A pipeline receives a CSV file expected to have 500 rows. After loading, len(data) returns 12. What does this most likely indicate?
5. Why is the file name typed manually in Cell 5 of this unit rather than being read automatically from S3?
Unit 5 Summary
What you covered in this unit
Loading a file into an active notebook environment so that code can navigate, inspect, and eventually process its contents.
Every dataset is a grid. Each row is one record. Each column is one category of information. Together they form a structured, navigable dataset.
Python counts from zero. The first row is at index 0, the second at index 1. Two index numbers together pinpoint one exact value in the grid.
Counting rows immediately after loading is a standard pipeline check. An unexpected row count is one of the earliest and most reliable signals that something went wrong.