Now that you have your environment set up with Python, NumPy, and Pandas installed, let's look at the tool you'll likely use most often for interactive data analysis: the Jupyter Notebook. Think of it as a digital lab notebook where you can write and run Python code, add explanatory text, display results like tables and plots, all in one place within your web browser.
A Jupyter Notebook is an open-source web application that allows you to create and share documents containing live code, equations, visualizations, and narrative text. The name "Jupyter" comes from the core programming languages it supports: Julia, Python, and R. Notebooks are widely used in data science because they make it easy to experiment with code, see results immediately, and document your thought process along the way.
The notebook documents themselves (.ipynb
files) store everything: your code, the output it produced, and any text or images you added. This makes them self-contained and easy to share.
The main working components of a Jupyter Notebook are cells and a kernel.
Cells: These are the building blocks of a notebook. There are two primary types:
Kernel: This is the computational engine running behind the scenes. When you run a code cell, the kernel executes that code. It maintains the state of your computation, meaning variables defined in one cell are available in subsequent cells within the same session. For this course, you'll be using the Python kernel.
Basic interaction flow in a Jupyter Notebook. Code from cells is sent to the kernel for execution, and results are displayed back in the notebook.
When you open a Jupyter Notebook, you'll see an interface primarily composed of these cells. Here are the fundamental actions:
Shift + Enter
. This runs the code in the current cell and automatically selects the next cell below it. Ctrl + Enter
runs the selected cell but keeps the focus on the same cell. You can also use the "Run" button in the toolbar. The order in which you run code cells matters, as later cells might depend on variables or imports defined in earlier ones.Esc
, then M
for Markdown or Y
for Code).Esc
, then A
to insert above, or B
to insert below).Esc
followed by D
, D
(press 'D' twice).Let's see a quick example. In a code cell, you might type:
import numpy as np
import pandas as pd
print("NumPy and Pandas imported successfully!")
Pressing Shift + Enter
executes this. If everything is set up correctly, you'll see the output:
NumPy and Pandas imported successfully!
Now, in the next code cell, you can use np
and pd
because the kernel remembers them from the previous execution:
my_array = np.array([1, 2, 3, 4])
my_series = pd.Series(['a', 'b', 'c'])
print(my_array)
print(my_series)
Running this cell would output:
[1 2 3 4]
0 a
1 b
2 c
dtype: object
Notice how the output appears directly beneath the cell that generated it.
Markdown cells allow you to add formatted text. You can create structure and explain your code. Here are a few basic examples:
# This is a Top-Level Heading
## This is a Second-Level Heading
Here is some regular text. You can explain what the next code cell does.
Use asterisks or dashes for bullet points:
* Item 1
* Item 2
* Sub-item
Or use numbers for ordered lists:
1. First step
2. Second step
You can add `inline code` using backticks.
When you run a Markdown cell (Shift + Enter
), the text is rendered with the specified formatting.
Jupyter Notebooks are particularly well-suited for the kind of work you'll be doing in this course:
.ipynb
file with others, and they can see your workflow, results, and explanations (they'll need Jupyter installed to run the code themselves).You'll typically start Jupyter Notebook from your terminal (after navigating to your working directory) by typing jupyter notebook
or jupyter lab
. Anaconda Navigator also provides a graphical way to launch it. As you proceed through this course, you'll gain much more hands-on experience using notebooks to work with NumPy and Pandas.
© 2025 ApX Machine Learning