Databricks Notebooks β Basics, Cells & Commands
Welcome back to ShopWave, our fictional retail company.
Youβve logged into Databricks, opened your cluster, and now itβs time to write your first notebook.
Your senior engineer says:
βThink of a notebook as your lab notebook β each cell is a step in your experiment.β
Letβs walk through it step by step.
π₯οΈ What Is a Databricks Notebook?β
A Databricks notebook is an interactive web-based tool where you can:
- Write code in Python, SQL, R, or Scala
- Run commands interactively
- Document your workflow with Markdown
- Visualize data and charts
- Collaborate with teammates in real-time
Itβs the central workspace for data engineers, analysts, and data scientists.
π§© Notebook Structure β Cells, Commands & Typesβ
A notebook is made up of cells. Each cell can contain:
1οΈβ£ Code Cellsβ
- Run your programming code (Python, SQL, Scala, R)
- Execute transformations, queries, or ML training
- Example:
# Python code cell
sales = spark.read.table("sales")
sales.show(5)
2οΈβ£ SQL Cellsβ
- Run queries directly against Delta tables
- Can also visualize data using built-in charting
-- SQL code cell
SELECT product_id, SUM(quantity) AS total_sold
FROM sales
GROUP BY product_id
ORDER BY total_sold DESC
LIMIT 10;
3οΈβ£ Markdown / Text Cellsβ
- Add notes, explanations, and documentation
- Supports headings, lists, links, and images
# Sales Analysis
This cell explains the top-selling products in Q3 2025.
π₯ Running Cellsβ
- Press Shift + Enter β runs the current cell and moves to the next
- Press Ctrl + Enter β runs the current cell only
- Press Alt + Enter β runs the current cell and inserts a new one below
Your ShopWave workflow:
- Engineer loads raw sales data in a Python cell
- Analyst runs a SQL query cell to summarize data
- Team adds Markdown notes for context
- Visualize results in the same notebook
π§ Magic Commands & Shortcutsβ
Databricks also has magic commands, which make notebooks super flexible:
| Command | Use Case |
|---|---|
%sql | Run SQL in a Python or Scala notebook |
%python | Switch back to Python if in SQL notebook |
%md | Render Markdown text |
%run ./notebook_path | Import and run another notebook |
%fs | Work with Databricks File System (DBFS) |
Shortcuts make you faster and improve collaboration.
π€ Collaboration Featuresβ
Notebooks arenβt just for solo workβthey are team-friendly:
- Real-time editing (like Google Docs)
- Comment on cells for discussion
- Version history to revert changes
- Git integration to track notebook changes
ShopWaveβs ML team uses this to experiment with models, then merge the notebook into production workflows seamlessly.
π Visualizations in Notebooksβ
You can create:
- Bar charts
- Line charts
- Pie charts
- Scatter plots
Directly from SQL queries or DataFrames.
For ShopWave, visualizing top-selling products by region is one click away.
π Quick Summaryβ
- Databricks notebooks are interactive coding and documentation tools.
- Comprised of cells: Code (Python/SQL/Scala/R), Markdown, and Visualizations.
- Magic commands enhance functionality.
- Collaboration is seamless with real-time editing, comments, version control, and Git integration.
- Notebooks are essential for data engineering, ML, analytics, and dashboard prep.
π Coming Next
π Databricks Security Basics β Tokens, Users & Groups