Where to put import statements in a jupyter notebook

1.3k Views Asked by At

I realized that I am not too sure of where to put my import statements in a exploratory jupyter notebook.

I am currently putting all my imports in a notebook together in a cell in the beginning. Is this proper style?

1

There are 1 best solutions below

0
KitaPDev On

There is really no rule that's set in stone for placing imports in a Jupyter notebook, at least that I know of. I prefer to put imports that I know I'll definitely use from the start, and as work progresses and more libraries are needed, then I'll import library in the next working cell.

After all, the point of using Jupyter notebook versus writing a python script is being able to develop and test each portion of your code separately. Once your code in Jupyter notebook is completely tested, you can go ahead and create a Python project and structure it accordingly.