Lessons / Part 7. Python, notebooks and the tools around them
34 Run the analysis where you can run it again
A notebook with one step per cell and a print after each shows what happened between the table and the figure, and runs again tomorrow.
What people usually ask
Run a regression on this table and show me the plot.
<table pasted into the chat>
What comes back
A figure drawn in a sandbox, with nothing to show what happened between the pasted table and the line on the plot, and no way to run it again.
Ask this instead
Do not run it here. Write a Jupyter notebook that I run myself.
First markdown cell: define notebook, cell and kernel in one line
each. Then one step per cell with a print after every step: load
pressure_runs.csv; print shape and head; fit a linear regression of
flow on pressure with scikit-learn; print intercept, slope and R2;
plot the points and the fitted line with axis labels and units.
Last markdown cell: "Restart kernel and run all before trusting a
figure", with one line on why. I will run it and paste the outputs
and any error text back, cell by cell, and we go on from there.
Attach: The table as a CSV file; then the printed outputs and errors pasted back, cell by cell.
Why it works: A notebook the reader runs shows every intermediate result and can be rerun on a clean kernel; a figure from a sandbox shows only its last line.
Drafted with Fable 5.1 from my notes; chosen and edited by me.