Python, from Zero, for AILesson 79 of 89

Module 8 · Numbers in bulk: NumPy, pandas and the vector under every model

Notebooks without hidden state: execution order, restart-and-run-all, and when to leave for a .py file

In this lesson

  • 8 min read
  • 9 reading sections
  • Knowledge check
  • Lesson 10 of 10 in this chapter

This chapter’s goalLoad a messy CSV into pandas, clean its missing values and types, group and join it into the table a question needs, convert it to a NumPy array of the right shape and dtype, compute cosine similarity between one vector and a hundred thousand in a single vectorised expression, plot the result to a file, and explain from memory layout why the array version runs a hundred times faster than the loop it replaced.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:43Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 11Free · no account needed
Lesson steps

What a notebook is underneath

Jupyter, Colab, Kaggle and VS Code’s notebook view all work the same way: a kernel (one Python process) sits behind the page, and each cell you run is sent to it. The kernel keeps every variable, import and function from every cell you have ever executed, in the order you executed them, regardless of where the cells sit on the page.

That is the whole power of a notebook (you load a large file once and explore it for an hour without reloading) and the whole danger. The page shows cells in one order. The kernel remembers a different one. The two drift apart the moment you edit a cell and re-run only some of them, and the number in the square brackets beside each cell ([7], [3], [12]) is the only visible record of the real order.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Stuck on something?Ask Divya, your AI tutor

How to cite: Addaly (2026) ‘Notebooks without hidden state: execution order, restart-and-run-all, and when to leave for a .py file’, in Python, from Zero, for AI. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/python-for-ai/notebooks-without-hidden-state (Accessed: 21 November 2026).