Unit 4 Cloud Pipelines Notes

Unit 4 — Your First Databricks Notebook | DataSoSi
Cloud Data Pipelines · Unit 4 of 12 · Databricks Foundations

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.

Think of a Databricks notebook the way you think of a kitchen worktop. The worktop itself does nothing — but it is where all the work happens. You lay out your ingredients (data), follow your recipe (code), and the meal (output) appears right there in front of you. The notebook is your worktop for data.
4 Sections
6 Hands-On Cells
No Prior Coding Needed
1 2 3 4 5 6 7 8 9 10 11 12

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

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.

Everyday Analogy — The Science Lab Notebook

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.

Notebook vs. Spreadsheet vs. Script

Many people already use spreadsheets for data work. Here is how a notebook compares:

ToolWhat It Does WellWhere 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 NotebookRun 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.
The Anatomy of a Notebook

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.

Unit4_First_Notebook — Python
Cell [1] Code
print(“Welcome to Databricks”)
Output Welcome to Databricks
Cell [2] Code
company_name = “DataSoSi”
print(company_name)
Output DataSoSi
Cell [3] Code
file_name = “sales_data.csv”
print(“Processing file:”, file_name)
Output Processing file: sales_data.csv
Why Cells Matter

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.

What Businesses Use Notebooks For
Data Cleaning and Preparation
A notebook reads a raw sales file, removes blank rows, standardizes column names, and writes the clean output — exactly the pipeline workflow you are building throughout this course.
Reporting and Analytics
A finance team runs a notebook each month that reads transaction data, calculates totals, and produces summary tables — replacing a manual spreadsheet process that previously took hours.
Automated Workflows
Lambda triggers a notebook the moment a new file arrives in S3. The notebook runs without anyone opening it, produces its output, and the pipeline continues — fully hands-free.
Exploration and Research
Analysts use notebooks to explore new datasets interactively — running one cell at a time, examining what the data looks like, and adjusting their approach as they go, before committing to a final workflow.

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.

1
Log into Databricks
Go to community.cloud.databricks.com and sign in with the account you created in Unit 1. You land on the Databricks home screen — the central workspace dashboard.
2
Create a new notebook
Click New in the left sidebar, then select Notebook. A dialog box appears asking for a name and a language.
3
Name and configure the notebook
Name it Unit4_First_Notebook. Set the default language to Python. Click Create. The notebook opens with one empty cell, ready for your first instruction.
4
Attach to a cluster
At the top of the notebook, you will see a dropdown that says Detached. Click it and select your cluster (the compute environment that will run your code). If no cluster exists, click Create a cluster and use the default settings. A notebook without a cluster is like a car without an engine — the interface is there, but nothing can run.
Everyday Analogy — The Cluster as a Power Supply

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.

Understanding the Notebook Interface
ElementWhat It IsWhat You Do With It
CellAn individual block where you write codeClick inside it, type your code, and press Shift + Enter or click Run
Run buttonThe triangle (▶) at the left of each cellClick it to execute only that cell — results appear below immediately
Output areaThe space directly beneath a cell after it runsRead the result, check for errors, and use it to inform the next cell
Add cell buttonThe + icon between cellsClick to add a new empty cell above or below the current one
Cluster indicatorThe dropdown at the top right of the notebookConfirms 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.

Cell 1 — Your First Output
Python Cell 1 — print()
print(“Welcome to Databricks”)
Expected Output
Welcome to Databricks
What Is Happening Here

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.

Cell 2 — Storing Information in a Variable
Python Cell 2 — Variables
company_name = “DataSoSi”
print(company_name)
Expected Output
DataSoSi
What Is Happening Here

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.

Cell 3 — Simulating a File Arriving in S3
Python Cell 3 — File Detection Simulation
file_name = “sales_data.csv”
print(“Processing file:”, file_name)
Expected Output
Processing file: sales_data.csv
What Is Happening Here

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.

Cell 4 — A Simple Business Calculation
Python Cell 4 — Profit Calculation
sales = 5000
expenses = 3200
profit = sales – expenses
print(“Profit:”, profit)
Expected Output
Profit: 1800
What Is Happening Here

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.

Cell 5 — Multiple Outputs: Simulating Pipeline Stages
Python Cell 5 — Pipeline Progress Log
print(“Step 1: File Received”)
print(“Step 2: Data Processed”)
print(“Step 3: Output Generated”)
Expected Output
Step 1: File Received Step 2: Data Processed Step 3: Output Generated
What Is Happening Here

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.

Cell 6 — Putting It Together
Python Cell 6 — Combined Mini Pipeline
file_name = “sales_data.csv”
company_name = “DataSoSi”

print(“Company:”, company_name)
print(“File being processed:”, file_name)
print(“Status: Ready for cleaning”)
Expected Output
Company: DataSoSi File being processed: sales_data.csv Status: Ready for cleaning
What Is Happening Here

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:

CSV
Business uploads a file to S3
A CSV file lands in the raw/ folder of the bucket you created in Unit 3. This is the event that starts everything.
↓
λ
Lambda detects the upload
The S3 trigger fires Lambda. Lambda does not process data — it passes the file name and location to Databricks and tells it to start running.
↓
NB
Your notebook runs automatically
The notebook from this unit — or a more advanced version of it — starts executing. The file_name variable is no longer set manually; Lambda supplies it. The notebook reads the file, processes it, and produces an output.
↓
OUT
Clean output is stored
The processed result is written back to the cleaned/ folder in S3 or to a Delta table. Dashboards, reports, and analysts read from this reliable, structured output.
Everyday Analogy — The Dishwasher

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.

Where You Are in the Course

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

The Notebook

An interactive document where code is written, run cell by cell, and results appear immediately below — the core working environment in Databricks.

Cells

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.

Variables

Named containers that store values — text, numbers, or file names — which the notebook can use and reuse throughout its logic without repeating the value.

Pipeline Connection

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.

Notebook Cell print() Variable String Integer Cluster Output Area Shift + Enter Pipeline Log