Exercise 3: Why Jupyter Notebooks Fit Data Science Work Better Than a Plain Script — Possible Solution ==================================================================== WHAT py1-1's OWN SCRIPT MODEL LOOKS LIKE ------------------------------ Per this chapter, "py1-1 introduced running Python as a plain script, top to bottom, once." Every time the script is run, execution starts fresh from the very first line and proceeds straight through to the end — there's no way to re-run only a small, changed portion of the code while keeping earlier results already computed. WHY THIS IS A POOR FIT FOR EXPLORATORY WORK SPECIFICALLY ------------------------------ Per this chapter, "data science work is exploratory and iterative by nature — you look at a dataset, try something, look at the result, adjust, try again — and a plain script re-run from the top every time that happens is genuinely slow to work with." If, say, loading and cleaning a large dataset takes real time, and a data scientist wants to try five different ways of visualizing the already-cleaned result, a plain script would force redoing the load-and-clean step every single time just to test a small visualization tweak — a real, practical cost that has nothing to do with the interesting part of the work. WHAT A NOTEBOOK CHANGES, PER THIS CHAPTER ------------------------------ Per this chapter, a Jupyter notebook is "made of individual, independently runnable cells: code cells that keep their own output (including inline charts) visible directly beneath them... Running one cell at a time, keeping earlier results in memory, and only re-running what actually changed is the standard way real data science work gets done." This directly solves the exact cost identified above: the expensive load-and-clean cell only needs to run once, and its result stays available in memory while the visualization cell is edited and re-run repeatedly on its own, with its output appearing immediately beneath it for quick visual comparison. WHY THIS DOESN'T MAKE SCRIPT-BASED PYTHON OBSOLETE ------------------------------ Per this chapter, notebooks are explicitly framed as "not a replacement for py1-1's own script model in general, just the better-fitting tool for this specific, exploratory kind of work." A script's own predictable, always-run-start-to-finish behavior is exactly the right property for code that needs to run unattended and reliably (a scheduled job, a deployed application) — properties that would actually be a liability during exploratory data analysis, where partial, resumable, inspectable execution is the more useful behavior. The two tools are suited to genuinely different kinds of tasks, not ranked better/worse in general. WHY THIS WORKS AS AN ANSWER ------------------------------ It contrasts the specific cost of the plain-script model for exploratory work (having to redo expensive earlier steps) with the specific mechanism notebooks use to avoid that cost (independently re-runnable cells retaining prior state), and explains, using the chapter's own explicit framing, why this is a task-fit distinction rather than a claim that one tool is simply better than the other.