Unit 5 Cloud Pipelines Notes

Unit 5 — Reading Data from S3 | DataSoSi
Cloud Data Pipelines · Unit 5 of 12 · Data Inspection

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.

Before a restaurant chef starts cooking, they inspect the delivery. They open every box, check for freshness, count the portions, and make sure nothing is missing or wrong before any heat touches the ingredients. Reading and inspecting data in Databricks is exactly this step — you open the dataset, look at what arrived, and confirm it is ready to work with before doing anything else.
4 Sections
5 Hands-On Cells
No Advanced Coding
1 2 3 4 5 6 7 8 9 10 11 12

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
Four sections. Select individually or expand all.

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.

Everyday Analogy — Opening the Delivery Box

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.

Where This Step Sits in the Pipeline
CSV
File uploaded to S3 raw/ folder
Covered in Unit 3
Done
↓
λ
Lambda detects upload and triggers notebook
Coming in Unit 9
Later
↓
READ
Databricks reads and inspects the dataset
This unit — the notebook loads the data and you examine its structure before any cleaning begins
Now
↓
CLN
Clean and transform the data
Coming in Unit 6
Next
↓
OUT
Write clean output to a table
Coming in Unit 7
Later
Why Inspect Before Processing?
Catch Problems Early
A file that arrived with fewer rows than expected, or with columns in the wrong order, will cause every downstream step to fail or produce wrong results. Inspection catches these issues before any processing happens.
Confirm the Right File
In a high-volume pipeline, files can arrive out of order or with naming errors. Checking the row count and column structure confirms that the file being processed is the one you expected — not last week’s version or a test file.
Build the Audit Trail
Logging what was found at inspection time — row count, column names, timestamp — gives you a record of the data as it arrived. If questions arise later about data quality, this log is your evidence.

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.

Everyday Analogy — The Classroom Register

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 Sales Dataset Used in This Unit

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.

Employee Sales ($) Region
Alice
500
West
Bob
700
East
Charlie
450
North
Understanding Python List Indexing

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.

Everyday Analogy — The Ground Floor

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).

IndexRow ContentsHow 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.

1
Upload your CSV to S3 first
Before opening Databricks, go to Amazon S3, open your raw/ folder, and upload a CSV file (e.g. sales_data.csv). This reinforces the habit of treating S3 as the data inbox — even when you are creating sample data inside the notebook for now, the real pipeline will read from this folder.
Cell 1 — Create the Dataset
Python Cell 1 — Load Sample Data
data = [
    [“Alice”, 500, “West”],
    [“Bob”, 700, “East”],
    [“Charlie”, 450, “North”]
]

print(data)
Expected Output
[[‘Alice’, 500, ‘West’], [‘Bob’, 700, ‘East’], [‘Charlie’, 450, ‘North’]]
What Is Happening Here

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.

Cell 2 — View One Row
Python Cell 2 — Access a Single Row
print(data[0])
Expected Output
[‘Alice’, 500, ‘West’]
What Is Happening Here

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.

Cell 3 — Retrieve One Specific Value
Python Cell 3 — Access a Specific Value
print(data[1][1])
Expected Output
700
What Is Happening Here

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.

Cell 4 — Count the Rows
Python Cell 4 — Row Count Validation
print(“Total Rows:”, len(data))
Expected Output
Total Rows: 3
What Is Happening Here

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.

Cell 5 — Simulate Reading from S3
Python Cell 5 — S3 Read Simulation
file_name = “sales_data.csv”
print(“Reading dataset from S3:”, file_name)
Expected Output
Reading dataset from S3: sales_data.csv
What Is Happening Here

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.

What Goes Wrong Without Inspection
Wrong File Processed
A pipeline receives last month’s sales file by mistake instead of this month’s. Without a row count check or a date column inspection, the pipeline processes it successfully — and produces a monthly report based entirely on old data. The error goes unnoticed until a manager questions why the numbers match the previous month exactly.
Truncated Upload
A large CSV file fails mid-upload due to a network issue. The first 200 rows land in S3, but the remaining 1,800 rows never arrive. Without a row count check, the pipeline processes the partial file and writes a summary showing 200 records instead of 2,000 — a figure that looks plausible enough to go unquestioned.
Shifted Columns
A supplier changes their CSV export format and adds a new column at position 0. Every column in the dataset shifts one position to the right. Without inspection, the pipeline reads the wrong columns — treating a product code as a sales amount, or a date as a region name — and produces clean-looking output with completely wrong values.
Empty Dataset
A scheduled overnight export runs but produces an empty file — zero rows — because the source system had a connection error. Without an inspection step, the pipeline processes an empty dataset and reports zero sales for the period. This triggers unnecessary alarm and investigation when a simple row count check at entry would have flagged the problem instantly.
The Principle Behind Inspection

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.

What Is Coming Next

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

Reading Data

Loading a file into an active notebook environment so that code can navigate, inspect, and eventually process its contents.

Rows and Columns

Every dataset is a grid. Each row is one record. Each column is one category of information. Together they form a structured, navigable dataset.

Index Numbering

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.

len() Validation

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.

Reading Data Dataset Row Column Index Zero-Based Indexing len() Row Count Data Inspection Validation Gate