Everything You Need To Know About Jupyter Notebooks
By: Bharath K
Tags: Data Science, Productivity, Artificial Intelligence, Programming, Jupyter Notebook

File:

Screenshot By Author

New Notebook: The name is self-explanatory as it allows you to create multiple new Notebooks for your Python or Data Science projects. Open: This command will redirect you to your local host and you can open other files from there. Make a copy: You can create duplicate copies of your Jupyter Notebook that will be useful for trying various experiments with your Data Science Projects. Save as: Used to save your Notebook with a specific path. Rename: You can use this command to Rename your Notebook or simply double click on the title header instead for performing the same action. Save and Checkpoint: As the name suggests it saves your progress and checkpoints the file accordingly. The shortcut key ctrl + s will perform an equivalent action. Revert to Checkpoint: If you ever mess up with while experimenting with the Jupyter Notebook, this is an useful command to revert back to your previous saved state and nullify your mistakes. Print Preview: Used to get only the code part of the Jupyter Notebook for a clean print. Download as: Allows you to download your Jupyter Notebook in various formats including HTML, IPython, .py format, etc., among many other options. Close and Halt: Ends your current running session of the Jupyter Notebook and returns you back to the local Host.

Kernel:

Screenshot By Author

The kernel is a computer program at the core of a computer’s operating system that has complete control over everything in the system. It is the “portion of the operating system code that is always resident in memory”, and facilitates interactions between hardware and software components.

A notebook kernel is a “computational engine” that executes the code contained in a Notebook document. The ipython kernel, referenced in this guide, executes python code. Kernels for many other languages exist (official kernels).

When you open a Notebook document, the associated kernel is automatically launched. When the notebook is executed (either cell-by-cell or with menu Cell -> Run All), the kernel performs the computation and produces the results. Depending on the type of computations, the kernel may consume significant CPU and RAM. Note that the RAM is not released until the kernel is shut-down.

Let us proceed to analyze the various functions in the Kernel menu icon that will be useful for Data Science projects.

Interrupt: Used to stop the execution or running of a particular cell. This command is useful when you have reached a desired result within a specific number of epochs or in case you made an error, and you realize this while running the code. Restart: Useful to restart the Kernel of the Notebook. Restart and Clear Output: Used to restart the Kernel of the Notebook and reset all the cells that were run previously. Restart and Run all: Used to restart the Kernel of the Notebook, and reset all the cells that were run previously, and finally re-run through all the cells of the Notebook. Reconnect: Used to reconnect to a dead kernel which might occur at times due to a lack of memory. Shutdown: Used to shutdown the current working Kernel of the Notebook. Change kernel: Allows you to switch Kernels.

Other Menu Options:

Screenshot By Author

Since we have already discussed the “File” and “Kernel options in the main menu bar in detail, let us briefly look at the other options and the functionalities they offer us.

Edit: Used to edit the cells and perform functionalities like adding, cutting, moving, or deletion of cell blocks.

Used to edit the cells and perform functionalities like adding, cutting, moving, or deletion of cell blocks. View: Used to change the appearance of the Notebook as per the users desire.

Used to change the appearance of the Notebook as per the users desire. Insert: Used to insert a cell block above or below a specific selected cell.

Used to insert a cell block above or below a specific selected cell. Cell: Used to run the various cells or select a specific cell type.

Used to run the various cells or select a specific cell type. Widgets: You can use widgets to build interactive GUIs for your notebooks. Widgets are eventful python objects that have a representation in the browser, often as a control like a slider, textbox, etc.

You can use widgets to build interactive GUIs for your notebooks. Widgets are eventful python objects that have a representation in the browser, often as a control like a slider, textbox, etc. Help: Provides help and also allows you to view the shortcut options available in the Jupyter Notebook.

Command Icon Palette:

We will discuss this icon palette starting from the first icon, which is the save option, until the end. This command palette will be useful for quickly completing the majority of your tasks.

Screenshot By Author

Save and Checkpoint: As the name suggests it saves your progress and checkpoints the file accordingly. The shortcut key ctrl + s will perform an equivalent action. Insert Cell Below: Adds a new cell below. Cut Selected Cells: Cuts the selected cells. Copy Selected Cells: Copies the selected cells. Paste Selected Cells: Pastes the selected cells. Move the selected cells upward. Move the selected cells downward. Run: Runs the particular selected cell. Interrupt: Used to stop the execution or running of a particular cell. Restart: Useful to restart the Kernel of the Notebook. Restart and Run all: Used to restart the Kernel of the Notebook, and reset all the cells that were run previously, and finally re-run through all the cells of the Notebook. Change Cell Type: Allows you the option to convert the type of cell into your desired type ranging from Code, Markdown, etc. Command Palette: Opens the command palette to perform various functions.

Running The Code Cells:

Screenshot By Author

You can run the notebook document step-by-step (one cell a time) by pressing crtl + enter for running the particular cell or shift + enter to run the current cell as well create a new cell below it. You can run the whole notebook in a single step by clicking on the menu Cell -> Run All.

The above image is a representation of how each of these cells can run as separate code blocks. In the first code cell you can notice that we have used the print statement for printing a basic “Hello World!” program.

However, similar to a command prompt or python shell, the variables defined, assigned, or obtained can be run at the end of the code cell or in a new code cell to receive the held value. The code cells [2] and [3] are a representation of the same.

Finally, the code cells can also be used as a calculator to perform a variety of tasks ranging from addition, subtraction, multiplication, division, power (**), and many more functions. You can also utilize these code blocks for programming your python or Data Science projects.