Skip to main content

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:

  1. Engineer loads raw sales data in a Python cell
  2. Analyst runs a SQL query cell to summarize data
  3. Team adds Markdown notes for context
  4. Visualize results in the same notebook

🧠 Magic Commands & Shortcuts​

Databricks also has magic commands, which make notebooks super flexible:

CommandUse Case
%sqlRun SQL in a Python or Scala notebook
%pythonSwitch back to Python if in SQL notebook
%mdRender Markdown text
%run ./notebook_pathImport and run another notebook
%fsWork 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