Site icon Runrex

What is Jupyter Notebook: 20 Tips

What is Jupyter Notebook: 20 Tips

When it comes to programming, at some point we all need to show our work. Most programming work is shared either as raw source code or as a compiled executable. As is discussed over at runrex.com, the source code provides complete information, but in a way, that is more “tell” than “show”. On the other hand, the executable shows us what the software does, but even when shipped with the source code it can be difficult to grasp exactly how it works. Therefore, imagine being able to view the code and execute it in the same UI, so that you could make changes to the code and view the results of these changes instantly, in real-time? This is exactly what Jupyter Notebook offers, but what is it? This article will look to help you know what it is.

What is Jupyter Notebook?

As the subject matter experts over at guttulus.com point out, the Jupyter Notebook is an incredibly powerful tool for interactively developing and presenting data science projects. It combines live code, graphics, visualizations, and text in sharable notebooks that run in a web browser.

What is a “notebook”?

To understand what Jupyter Notebook is, you need to understand what a “notebook” is. As covered over at runrex.com, a notebook integrates code and its output into a single document that combines visualizations, narrative text, mathematical equations, and other rich media. It is, therefore, a single document where you can run code, display the output, and also add explanations, formulas, charts, and make your work more transparent, understandable, repeatable, and shareable.

Installation

The easiest way for a beginner to get started with Jupyter Notebook is by installing Anaconda. As detailed over at guttulus.com, Anaconda is the most widely used Python distribution for data science and comes pre-loaded with all the most popular libraries and tools. If you are a more advanced user with Python already installed and you prefer to manage your packages manually, you can just use pip to install Jupyter Notebook.

Jupyter Notebook components

Jupyter Notebook can include several kinds of ingredients, each organized into discrete blocks:

Text and HTML

Plain text, or text annotated in the Markdown syntax to generate HTML, can be inserted into the document at any point. CSS styling can also be included inline or added to the template used to generate the notebook.

Code and output

The code in Jupyter Notebook is typically Python code, although it is possible to add support in your Jupyter environment for other languages such as R or Julia. The results of executed code appear immediately after the code blocks, and the code blocks can be executed and re-executed in any order you like, and as often as you like.

Visualizations

As is revealed in discussions on the same over at runrex.com, graphics and charts can be generated from code, by way of modules like Matplotlib, Plotly, or Bokeh. Like output, these visualizations appear inline next to the code that generates them. However, code can also be configured to write them out to external files if needed.

Multimedia

Since Jupyter Notebook is built on web technology, it can display all the types of multimedia supported in a web page as pointed out by the subject matter experts over at guttulus.com. You can include them in a notebook as HTML elements, or you can generate them programmatically by way of the IPython.display module.

Data

From discussions on the same over at runrex.com, data can be provided in a separate file alongside the .ipynb file that constitutes a Jupyter Notebook notebook, or it can be imported programmatically. For instance, by including code in the notebook to download the data from a public internet repository or to access it via a database connection.

Jupyter use cases

The most common use cases for Jupyter Notebook are data science, mathematics, and other research projects that involve visualizations of data or formulas. However, apart from those, there are plenty of other use cases, including:

Sharing a visualization, with or without interactivity

People often share the results of a data visualization as a static image. However, this is only useful up to a point. By sharing a Jupyter notebook, you allow your target audience to dive in and play around, allowing them to gain a thorough understanding of the data, interactively.

Documenting a process with code

Many programmers who blog about their programing experiences write up their posts in a Jupyter notebook, which is one of its most common case uses as it allows one to document a process with code, and for the audience to understand it. Others can then download their notebook and recreate the exercise.

Sharing code and data generally

As the subject matter experts over at guttulus.com point out, Jupyter Notebook also allows users to share code and data. All you need to do to share a Jupyter notebook and its associated data files is pack it up into an archive.

Live documentation for a library or module

Most documentation for Python modules is static as covered over at runrex.com. A Jupyter notebook can, therefore, be used as an interactive sandbox for learning how a module works. Any Python module that runs well in a notebook interface, which is essentially anything that writes to stdout as part of its behavior, is a good candidate for this.

These are some of the common Jupyter Notebook use cases.

JupyterLab

A next-generation user interface for Jupyter Notebook, called JupyterLab, is now available and considered ready for production use. As is articulated over at guttulus.com, JupyterLab is more malleable than a conventional Jupyter Notebook, allowing users to drag-and-drop cells within and between notebooks and to arrange the workspace into separate tabs and subsections. Code can run directly from text files as well as Jupyter Notebook files, and many common file formats for both code and data can be rendered with live previews.

Jupyter Notebook benefits

Originally developed for data science applications written in Python, R, and Julia, Jupyter Notebook is useful in all manner of ways for all kinds of projects, including:

Data visualizations

Most people have their first exposure to Jupyter Notebook by way of a data visualization, a shared notebook that includes a rendering of some data set as a graphic. Jupyter Notebook lets you author visualizations, but also share them allowing interactive changes to the shared code and data set.

Code sharing

While cloud services like GitHub and Pastebin provide ways to share code, they are largely non-interactive. With a Jupyter Notebook, you can view code, execute it, and display the results directly in your web browser.

Documenting code samples

If you have a piece of code and you want to explain line-by-line how it works, with live feedback all along the way, you could embed it in a Jupyter Notebook as articulated over at runrex.com. Best of all, the code will remain fully functional, which means you can add interactivity along with the explanation, showing, and telling at the same time.

Live interactions with code

As the gurus over at guttulus.com point out, Jupyter Notebook isn’t static; it can be edited and re-run incrementally in real-time, with feedback provided directly in the browser. Notebooks can also embed user controls such as sliders or text input fields that can be used as input sources for code.

Jupyter Notebook limitations

While Jupyter Notebook is extremely powerful and useful, it still has some limitations that need to be taken into account. They include:

Notebooks aren’t self-contained

According to runrex.com, this is the single biggest drawback of using Jupyter Notebook. Notebooks require both the Jupyter runtime and the libraries you plan on using, and while a few strategies exist for creating self-contained Jupyter Notebooks, none of them is officially supported.

Session state cannot be saved easily

The state of any code running in a Jupyter notebook cannot be preserved and restored with Jupyter Notebook’s default toolset. This means that every time you load the notebook, you will need to re-run the code to restore its state.

No interactive debugging or other IDE features

Finally, Jupyter Notebook is not a full-blown development environment for Python. Therefore, many of the features you would expect to find in an IDE such as interactive debugging, code completion, and module management, are not available there.

This article only just begins to scratch the surface as far as this topic is concerned, and you can uncover more details by checking out the highly-regarded runrex.com and guttulus.com.

Exit mobile version