Unit 4 Cloud Pipelines Notes
Your First Databricks Notebook
Open a notebook, write your first lines of Python, and see results appear instantly — no experience required. By the end of this unit, you will have a working notebook that simulates a real pipeline in action.
Learning Objectives
- Explain what a Databricks notebook is and how it differs from a spreadsheet or a script file
- Create a new notebook, name it correctly, and attach it to a compute cluster
- Write and run six notebook cells covering output, variables, file simulation, calculations, and pipeline status
- Explain what each line of code does in plain language — no jargon required
- Describe how a completed notebook connects to Lambda and S3 in an automated pipeline
A Databricks notebook is an interactive document where you write code, run it immediately, and see the results appear directly below — all in one place. It combines the structure of a document with the power of a programming environment.
In a science class, a lab notebook has a specific format: you write your hypothesis, record your steps, note your observations, and document your results — all in order, all in one place. A Databricks notebook works identically. You write an instruction (code), run it (the experiment), observe the result (the output), and move to the next step. The entire record stays in the notebook, readable by anyone who opens it.
Many people already use spreadsheets for data work. Here is how a notebook compares:
| Tool | What It Does Well | Where It Breaks Down |
|---|---|---|
| Spreadsheet (Excel) | Great for small, manually managed datasets. Easy to view and edit values directly. | Cannot process millions of rows. Formulas break when data changes structure. No automation. No audit trail of logic. |
| Script File (.py) | Runs code end-to-end. Good for production automation. | You cannot see results until the whole script finishes. Harder to explore and debug step by step. |
| Databricks Notebook | Run one cell at a time and see results instantly. Combine code, results, and notes in one document. Scales to any data size. Can be triggered automatically by Lambda. | Requires a compute cluster to run. Lives in the cloud, not on your desktop. |
Every notebook is made up of cells. Each cell is an independent unit — it contains a piece of code, and when you run it, the result appears directly below. Think of cells as individual steps in a recipe: you complete one step, see the result, and move to the next.
print(company_name)
print(“Processing file:”, file_name)
Running code one cell at a time means you can check each step before moving forward. If something goes wrong, you know exactly which cell caused it — you do not have to search through hundreds of lines. This makes notebooks far easier to debug and understand than a single long script, especially when you are learning.
Before you write any code, you need to set up the environment. These steps take less than two minutes and only need to be done once per unit.
Imagine a notebook as a microwave and the cluster as the electrical socket it plugs into. The microwave (notebook) contains all your instructions — when to heat, for how long, at what power. But without plugging it into the socket (cluster), pressing any button does nothing. Attaching your notebook to a cluster is literally plugging in before you start.
| Element | What It Is | What You Do With It |
|---|---|---|
| Cell | An individual block where you write code | Click inside it, type your code, and press Shift + Enter or click Run |
| Run button | The triangle (▶) at the left of each cell | Click it to execute only that cell — results appear below immediately |
| Output area | The space directly beneath a cell after it runs | Read the result, check for errors, and use it to inform the next cell |
| Add cell button | The + icon between cells | Click to add a new empty cell above or below the current one |
| Cluster indicator | The dropdown at the top right of the notebook | Confirms whether your notebook is connected to compute power and ready to run |
Run each cell in order. Do not skip ahead — each cell builds on the concepts introduced in the one before it. After each cell, read the explanation before moving to the next.
print() is an instruction that tells the notebook to display whatever is inside the parentheses. The text between the quotation marks is called a string — a piece of text data. Think of print() as the notebook’s way of speaking: you tell it what to say, and it says it. This is the most fundamental operation in any programming language — confirming that code is running and producing visible output.
print(company_name)
A variable is a named container that holds a value. The line company_name = "DataSoSi" creates a container called company_name and stores the text “DataSoSi” inside it. The second line prints whatever is stored in that container. Think of a variable like a sticky note on your desk — you write a label on it (company_name) and the value underneath it (DataSoSi). Any time you need that value later, you just refer to the label instead of retyping the value. In a real pipeline, variables hold file names, column names, date ranges, and other values that the notebook refers to throughout its logic.
print(“Processing file:”, file_name)
This cell simulates the first moment in the pipeline: a file has been detected. The variable file_name stores the name of the incoming file. In a real automated pipeline, Lambda would pass this value to the notebook automatically — the actual file name from S3 would populate this variable the instant the pipeline triggered. For now, you are setting it manually to practise the pattern. The print statement combines a fixed label (“Processing file:”) with the variable’s value — this kind of confirmation message is standard practice in real pipeline notebooks to confirm which file is currently being handled.
expenses = 3200
profit = sales – expenses
print(“Profit:”, profit)
Three variables are created: sales, expenses, and profit. Notice that sales and expenses hold numbers, not text — there are no quotation marks around them. Python treats numbers and text differently, which matters when you want to do arithmetic. The line profit = sales - expenses performs the subtraction and stores the result in a new variable. In a real business pipeline, these values would not be typed manually — they would come from a CSV file or a database query. The logic is identical: read two columns, subtract one from the other, store the result. Databricks is used this way every day by finance, operations, and HR teams to produce figures that used to require hours of manual spreadsheet work.
print(“Step 2: Data Processed”)
print(“Step 3: Output Generated”)
A single cell can contain multiple lines of code, and all of them run in sequence when you execute the cell. Each print statement represents one stage of the pipeline confirming its completion. In a production notebook, these messages would appear in the run logs — allowing anyone monitoring the pipeline to see exactly how far it has progressed. If Step 2 never prints, something went wrong between file receipt and data processing. This pattern — printing a confirmation at each meaningful step — is one of the most practical habits in data engineering, because it makes pipelines transparent and much easier to debug when something goes wrong.
company_name = “DataSoSi”
print(“Company:”, company_name)
print(“File being processed:”, file_name)
print(“Status: Ready for cleaning”)
This cell brings together everything from the previous five: multiple variables, combined with print statements, producing a structured summary that reads like a real pipeline log entry. In Unit 5, instead of typing the file name manually, your notebook will read a real CSV file from S3 and the values will come from the data itself. This cell is the last manual simulation — from here, the pipeline becomes real.
Every cell you just ran is a building block. Right now, you are triggering the notebook yourself by clicking Run. That changes in later units. Here is how everything connects:
Right now, running your notebook by clicking Run is like washing dishes by hand — you are doing each step manually, which is fine for learning. Connecting the notebook to Lambda is like loading the dishwasher and pressing start: you set it up once, and from then on, every time dishes arrive (files arrive in S3), the machine runs the full cycle automatically. The cleaning logic does not change — only who triggers it does.
You have now built the first three physical components of the pipeline: an S3 bucket (Unit 3), a Databricks notebook (this unit), and an understanding of the data lifecycle (Units 1 and 2). Unit 5 connects the notebook to the S3 bucket for the first time — your notebook will read a real file from real cloud storage and display its contents.
Knowledge Check
Five questions covering the key concepts from Unit 4. Select the best answer for each question.
1. What is a notebook cell in Databricks?
2. In Cell 4 of this unit, what does the line profit = sales - expenses do?
3. Why must a notebook be attached to a cluster before it can run?
4. What is the practical value of printing a status message at each step of a pipeline notebook?
5. In this unit, the file_name variable is set manually. What will supply this value automatically in a real pipeline?
Unit 4 Summary
What you covered in this unit
An interactive document where code is written, run cell by cell, and results appear immediately below — the core working environment in Databricks.
Each cell is an independent step. Running cells one at a time makes it easy to check results, catch errors, and understand exactly what is happening at each stage.
Named containers that store values — text, numbers, or file names — which the notebook can use and reuse throughout its logic without repeating the value.
In later units, Lambda will trigger this notebook automatically. The file_name variable will be passed from S3 instead of typed manually — making the whole workflow hands-free.