Jupyter Notebook Tutorial: Introduction, Setup, and Walkthrough
Based on Corey Schafer's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.
Jupyter Notebooks let users edit and rerun individual cells so plots and outputs update immediately in the browser.
Briefing
Jupyter Notebooks turn code, results, plots, and explanations into a single interactive document—so users can run computations in small steps, see outputs immediately in the browser, and even reproduce published research workflows. The tutorial opens by contrasting notebooks with static formats like PDFs: charts are generated live by the code, and changing a parameter (like a plot label) and rerunning a single cell updates the visualization instantly. That interactive loop—edit, execute, inspect—helps explain why scientific groups and research teams increasingly publish notebooks alongside their findings, including an example inspired by LIGO’s gravitational-wave work, where markdown instructions sit next to executable Python and generated figures.
From there, the walkthrough focuses on getting started. Installation is recommended via Anaconda because it bundles Jupyter, though pip-based installation is also available. After starting a notebook server (defaulting to localhost port 8888), the user creates a new notebook by selecting an appropriate kernel—essentially the programming-language runtime. The tutorial then emphasizes the notebook’s two operating modes: command mode for managing cells (add, delete, move) and edit mode for changing cell contents. Keyboard shortcuts are highlighted for switching modes and for executing cells.
Execution behavior is treated as a core concept. Running a cell can either keep focus on the current cell, move selection to the next cell, or insert a new cell below—each with different outcomes. The tutorial also explains why notebooks behave unlike traditional scripts: cells don’t have to run top-to-bottom. Instead, the “In [ ] / Out [ ]” numbering tracks the order of execution, which can cause variables to hold values from earlier runs even if the assignment appears later in the document. When state gets confusing, “Run all” restores a top-to-bottom execution order, and there are options to run only cells above or below the current one.
To make notebooks readable, the tutorial shows how to add markdown cells that render into HTML (headers, lists, emphasis, and more). It then introduces notebook “special commands” and “magics.” A leading exclamation mark runs bash commands directly (for example, pip list). Magics—prefixed with % or %%—provide notebook-specific utilities such as %lsmagic to list available commands, %pwd and %ls to inspect the environment, and %matplotlib inline to display Matplotlib plots inside the notebook. Without that inline setting, plotting can appear to hang until the kernel is restarted.
Additional cell magics demonstrate richer output: rendering HTML via %%html (including embedding an iframe), executing JavaScript, and timing code with %timeit. The tutorial also shows that simply printing a pandas DataFrame renders it neatly in the notebook, making exploratory data analysis more convenient than running separate scripts.
Finally, it covers practical workflow features: exporting notebooks to formats like HTML for sharing, understanding that notebook files are JSON under the hood, and creating multiple kernels—such as Python 2—either through Anaconda environments or pip-based kernel installation. To build familiarity, it points to Jupyter/IPython galleries on GitHub where users can download example notebooks (like numerical integration tutorials) and inspect the exact code behind the results.
Cornell Notes
Jupyter Notebooks combine executable code, rendered text (markdown), and live outputs like plots and DataFrame tables in one document. The key operational idea is that cells run independently: execution order is tracked by the “In [ ] / Out [ ]” numbers, so variables can change based on what was run earlier rather than what appears earlier. The tutorial shows how to install Jupyter (preferably via Anaconda), start a local notebook server, choose kernels, and use command/edit modes. It also demonstrates notebook magics and special commands—running bash with “!” and using %/%% magics for tasks like listing magics, enabling inline Matplotlib, rendering HTML, and timing code. Exporting notebooks to HTML and using multiple kernels (including Python 2 via Anaconda environments) rounds out the setup for sharing and experimentation.
Why do Jupyter Notebooks feel different from running a Python script top-to-bottom?
What’s the practical difference between command mode and edit mode in a notebook?
How do you execute a cell, and what do the three run options change?
What are “magics,” and how do they help beyond normal Python?
How can notebooks display rich content like plots, HTML, and DataFrames?
How do kernels and multiple Python versions fit into notebook setup?
Review Questions
- What problems can arise if you assume notebook cells run strictly from top to bottom, and how do the “In [ ] / Out [ ]” numbers help diagnose them?
- Which magic command enables Matplotlib plots to render inside the notebook, and what happens if you try to display a plot without it?
- How do the three execution options (run, run and select below, run and insert below) differ in terms of cell selection and insertion?
Key Points
- 1
Jupyter Notebooks let users edit and rerun individual cells so plots and outputs update immediately in the browser.
- 2
A notebook’s two modes—command mode and edit mode—control whether the user manages cells or edits cell content.
- 3
Execution order is independent of visual order; “In [ ] / Out [ ]” numbers track what ran when and can affect variable values.
- 4
Markdown cells render into formatted HTML, making notebooks readable like a tutorial or report with embedded results.
- 5
Notebook magics (% and %%) and “!” shell escapes enable environment commands, inline plotting, HTML rendering, and timing without leaving the notebook.
- 6
Exporting notebooks (e.g., to HTML) supports sharing code plus outputs, and notebook files are stored as JSON.
- 7
Multiple kernels allow different runtimes (such as Python 2 vs Python 3), typically managed via Anaconda environments or kernel installation steps.