Using Jupyter Notebook for Data Exploration
Python combines the breadth of a general-purpose language with the approachability of domain-specific scripting tools, and it offers libraries for loading, visualizing, and analyzing data.
A Hunch About Sensor Readings
Imagine you have a spreadsheet of sensor readings and a hunch that something in it is wrong. You could write a complete program, run it, read a long report, and then start over. Or you could ask one question at a time, look at each answer immediately, and let the answer shape your next question. Most people who work with data find the second approach far more productive. This article explains why Python supports that style of working, and how Jupyter Notebook makes it practical.
What do you think happens?
Before reading on: the readings are 4, 5, 6, and 40. What is their average?
Reveal answer
13.75
The four values add to 55, and 55 divided by 4 is 13.75. The single value 40 pulls the average well above the other three. Keep this suspicious value in mind, because the rest of this article uses it to trace one analysis across several rounds.
Why Data Work Moves in Rounds
Machine learning and data analysis are fundamentally iterative. In these processes the data drives the analysis. You rarely know in advance which questions will matter, which values are suspicious, or which method will fit. You discover those things by looking at the data, forming a judgment, and trying again. Each round depends on what the previous round revealed, so the speed and comfort of each round largely determine how well the whole process goes.
The loop is a general picture of the work, not a description of any specific tool's internals. The key idea is that the inspection step feeds back into the next action. Each pass through the loop can change the data, the question, or the method. If every small check requires writing and running a full program from scratch, the cycle becomes slow, and people stop exploring. Interactive use of Python, whether from a terminal or from a tool such as Jupyter Notebook, supports quick iteration because you can act on each result immediately.
Tracing the Sensor Average Round by Round
Rather than planning the whole analysis at once, take the suspicious readings one round at a time and watch how the picture changes. The example below is an original illustration of the iterative pattern the source describes.
Three rounds on one suspicious list
A list of four sensor readings contains a value that may be wrong. Compute the average, decide whether to filter, and recompute.
- 1Round 1: compute the first average
Sum the four readings to get 55, then divide by the count of 4. The result is 13.75, which looks high compared with the first three values.
- 2Round 1: inspect the result
The average is pulled upward by 40. Nothing is permanent yet. The round has only revealed that the average looks high.
- 3Round 2: revise the analysis
Because of the observation from round 1, keep only readings below 20 and recompute. Had round 1 looked reasonable, there would have been no reason to filter anything.
- 4Round 2: inspect the new result
The filtered list is 4, 5, 6 and its average is 5.0. The change in result came from what the data showed at the previous step.
The first round exposed a suspicious value, and the second round produced a much more stable average of 5.0. Each round was chosen because of what the previous one revealed.
13.75- Round 1: the full list, including the suspicious 40
sum(readings)adds the values to 55, andlen(readings)counts 4 items
[4, 5, 6]
5.0- Round 2: the filter is chosen because of the round 1 result
- The list is replaced with the filtered version, so later rounds build on it
Why Python Suits Iterative Work
Python is used across data science because it offers two qualities that are often found in separate tools. The first is the breadth of a general-purpose programming language, which can handle everything from reading files to building larger software systems. The second is the approachability usually associated with domain-specific scripting languages such as MATLAB or R, which are designed to make a narrow set of tasks quick to express. Python sits between these two worlds: it is capable enough for serious work, yet simple enough that a newcomer can read and write it without much ceremony.
Breadth matters because real data projects rarely stay inside one task. A project may need to load data from files, plot it, compute statistics, process text, or work with images. Python has libraries for each of these areas. Taken together, that collection gives a data scientist a set of tools that can be combined, rather than a single tool that covers one job well.
What Jupyter Notebook Is
Jupyter Notebook is an interactive environment for running code in the browser.
The key phrase in that definition is in the browser. Instead of installing a standalone program that opens its own window and runs scripts from start to finish, you open the notebook through a web browser and run code from there. The word interactive tells you the intended use: you run some code, see what it produces, and then decide what to run next. Most of the Python many people write lives in a single file that is edited and then run as a whole. That style suits finished programs, but data work often proceeds differently. You load data, look at it, try a calculation, notice something odd, and adjust. A tool that moves smoothly between writing code and inspecting its results fits this rhythm much better.
Code, Text, and Images in One Document
Because code, text, and images share one document, a notebook can tell the whole story of an analysis: the question being asked, the code that answers it, the output that comes back, and the notes explaining what the output means. This is the main reason the environment is useful for communicating results, not just for running calculations.
Picture the sensor analysis as a notebook. A text cell states the goal: check whether the readings have a suspicious value. Directly below it, a code cell computes the average. Beneath that code, the printed result 13.75 appears, followed by a text cell noting that 40 seems out of range. The reader sees the question, the method, and the answer together, in order.
Exploratory data analysis is the stage where you have data but not yet a firm plan, so you examine it, test ideas, and look for patterns before committing to a conclusion. The source singles out this stage as a great use for Jupyter Notebook, and it is widely used by data scientists for that reason. An environment that runs code in small, inspectable steps and keeps the results visible alongside your notes supports that back-and-forth well.
Kernel Memory Across Cells
A notebook is divided into cells, and you can run them in any order. The Python process that executes your code holds its variables between runs. That means a variable set by one cell is still available to the next cell, and re-running a cell changes what the process holds without automatically re-running the cells that depended on it. The diagram traces that behavior for two cells.
8
8- The first print shows y computed from x = 4
- Changing x does not recompute y on its own, so the second print still shows 8
Many Languages, One Course Choice
The environment supports many programming languages, and this course uses its Python support. The notebook interface is the part you see in the browser, and language-specific components do the work of running code written in each language. Choosing one language for the course lets every example in this material run the same way.
Mistakes That Slow Iterative Analysis
Common mistake Assuming the notebook shows the current state of every variable
What it looks likeRe-running cell 1 with x = 10 and then printing y, which still shows 8.
Why it failsThe notebook displays cells in order, but the process keeps the values from the most recent runs, which may not match the cells above.
Do this insteadAfter changing a cell that others depend on, re-run the dependent cells too, or restart and run the notebook from the top.
Common mistake Running cells out of order and then trusting the result
What it looks likeRunning a cell that uses a variable defined in a cell further down the page.
Why it failsThe result depends on the history of runs, not on the order you read the page, so a reader may not reproduce it.
Common mistake Treating one output as a final answer
What it looks likeReporting the average of 13.75 without checking the suspicious value of 40.
Why it failsGood iterative work treats each result as input to a judgment, not as a finished conclusion.
Do this insteadInspect the output, decide what it suggests, and run the next round before concluding.
Common mistake Writing a whole program for every small check
Why it failsEach check then costs a full write-and-run cycle, which makes the loop slow and discourages exploration.
Do this insteadSend short pieces of code to run and act on each result immediately.
Keeping a Record of Each Round
Good iterative work keeps a record of changes. In a notebook, this often means leaving text cells between code cells that state what each round tried and what it showed, so that the path from the first average to the filtered average can be followed later. Keep the record readable for someone else, because the notebook is also a document for communicating results.
Try One More Round
The readings are 10, 12, 11, and 95. Compute the average once with all four values. Then decide whether the 95 looks suspicious, filter it out, and compute the average again. Write down what each round showed before you run the next one.
Hints
- Sum the four values first, then divide by 4.
- Choose a threshold based on the other readings, such as keeping values below 50.
- Compare the two averages and ask whether the second one better matches the typical reading.
Key Takeaways
- Data analysis and machine learning are iterative: each round of running code and inspecting results drives the next step, so quick feedback matters.
- Python combines the breadth of a general-purpose language with the approachability of scripting tools, and its libraries cover loading, visualizing, and analyzing data.
- Jupyter Notebook is an interactive environment for running code in the browser, and one document can hold code, text, and images together.
- The notebook's running Python process keeps variable values between cell runs, so re-running cells out of order can leave stale values that the visible page does not show.
- Keep a readable record of each round, treat each result as input to a judgment, and restart and re-run from the top when results seem inconsistent.