Module 05
So you want to run Jupyter notebooks
Jupyter notebooks are where exploratory work, notes, plots, and “what on earth did I do yesterday?” can live in the same place.
Install Jupyter in your environment
If you are using venv and pip:
python -m pip install notebook jupyterlab matplotlib pandas numpy
If you are using conda:
conda install jupyterlab notebook matplotlib pandas numpy
Installing inside the active environment keeps your notebooks and dependencies aligned with the same project setup.
If setup has felt heavy so far, slow down here. Jupyter becomes much easier once you are confident about which environment is active.
Quick environment test before launching
python -c "import pandas, numpy, matplotlib; print('packages look good')"
Launch a notebook session
Start in the folder where you want your notebooks to live.
jupyter lab
If you prefer the classic notebook interface, use:
jupyter notebook
Your browser should open automatically. If it does not, copy the local URL printed in the terminal into a browser.
What to notice the first time
- The terminal stays busy because it is running the Jupyter server.
- The browser is only the interface. The actual Python work happens in the kernel.
- Closing the browser tab is not always the same as fully stopping Jupyter.
Shutting Jupyter down cleanly
Ctrl-C
y
Notebook vocabulary
- Cell: a block that holds code or markdown.
- Kernel: the Python process running your code.
- Output: text, tables, plots, or errors generated by a cell.
- Working directory: the folder the notebook sees by default.
Example 1: inspect a small microscopy-style table
Create a notebook and run the following cells. The example mimics simple per-cell measurements you might export from an image-analysis tool.
import pandas as pd
cells = pd.DataFrame(
{
"cell_id": ["c1", "c2", "c3", "c4"],
"condition": ["control", "control", "treated", "treated"],
"area_um2": [3.2, 3.5, 4.1, 4.4],
"mean_intensity": [120, 115, 142, 151],
}
)
cells
cells.groupby("condition")[["area_um2", "mean_intensity"]].mean()
This is the kind of small, interpretable example that helps learners understand what notebooks are good for before dealing with larger datasets.
Extra table operations to try
cells["area_um2"].mean()
cells["mean_intensity"].max()
cells[cells["condition"] == "treated"]
Example 2: make a quick plot
import matplotlib.pyplot as plt
cells.plot(x="cell_id", y="mean_intensity", kind="bar", legend=False)
plt.ylabel("Mean intensity")
plt.title("Per-cell fluorescence signal")
plt.tight_layout()
This kind of plot is a good first step for checking whether your export looks plausible before you move into more formal analysis.
Alternative plot
cells.plot.scatter(x="area_um2", y="mean_intensity")
plt.title("Area vs intensity")
plt.tight_layout()
Example 3: write your interpretation next to the code
Add a markdown cell below the plot and answer questions like:
- Do treated cells appear brighter on average?
- What would you want to measure next?
- Would you trust this pattern yet, or do you need more samples?
Example 4: work with a small image-like array
import numpy as np
import matplotlib.pyplot as plt
image = np.array(
[
[2, 3, 4, 4, 3],
[2, 6, 9, 7, 3],
[1, 7, 12, 8, 2],
[1, 5, 7, 5, 2],
[1, 2, 3, 2, 1],
]
)
plt.imshow(image, cmap="magma")
plt.colorbar(label="Intensity")
plt.title("Toy microscopy-like image")
plt.show()
print("Mean intensity:", image.mean())
print("Max intensity:", image.max())
Exercises
- Change one treated cell intensity and rerun the summary.
- Add a new column called
is_dividingwithTrueorFalsevalues. - Group by condition and count how many cells are labelled dividing.
- Write one markdown cell explaining what the plotted values might represent biologically.
Sample notebooks in this repo
- Cell measurements intro for grouped summaries and quick plotting.
- Image QC exercises for simple array-based image inspection practice.
Good notebook habits
- Restart and run all cells before sharing a notebook.
- Use markdown cells to explain what each section is doing.
- Keep raw data files outside the notebook itself.
- Give the notebook a descriptive filename linked to the experiment.
Troubleshooting notebook sessions
- If an import fails, confirm the environment is active and install into that same environment.
- If outputs seem inconsistent, restart the kernel and run all cells from the top.
- If the notebook opens in the wrong folder, stop Jupyter and relaunch it from the folder you want.
- If you are confused, build a fresh notebook with the smallest possible example.
Stop here for today if needed
A good stopping point is when you can launch Jupyter, run a few cells, and write one markdown explanation of the result. That is already enough to count as a meaningful notebook workflow.
Troubleshooting
- If
jupyteris not found, your environment may not be active. - If the browser page loads but cells fail, restart the kernel.
- If imports fail, install the missing package into the same environment as Jupyter.
- If notebooks open in the wrong folder, launch Jupyter from the project directory you actually want.