Python for all (2): What are Jupyter Notebooks?

Paloma Recuero de los Santos    30 January, 2019
What are the Jupyter Notebooks? The Jupyter Notebooks is maybe the most well know application of the Jupyter Project, created in 2014 with the objective of developing open-source software, open-standards, and interactive computer services compatible with different programming languages.

Jupyter Notebooks is a web application, also the open code that allows us to create and share documents with the live code, equations, visualizations and explicative text. These documents register the whole development process and, the most interesting thing, they can be easily shared with other people through email, dropbox, control systems such as git/GitHub and nbviewer.

Amongst its uses are:
  • The cleaning and transformation of data
  • Numerical simulation
  • Statistical modelling
  • Automatic learning
  • And much more

Why Jupyter?

As a curiosity, they ´christened´ it Jupyter for different reasons. On the one hand, for the scientific connotations to the allusion that the planet “Jupiter” brings, whose moons were protagonists of what is considered one of the first scientific publications supported by data, thus guaranteeing its reproducibility. Given that one of the objectives that inspired the Jupyter project is precisely this: facilitate the sharing and reproducibility of projects and experiments (scientific and all types), its creators decided to reflect this in its name. On the other hand, although Jupyter isn’t exactly an acronym, it pays tribute to Julia, Python and R, the programming languages running to support this environment. In particular, the central ´y´ was chosen to pay homage to the Python heritage, since Jupyter emerges as an evolution of iPython.

Who uses it?

Anyone who works in software development or the technological environment in the broadest sense, from the secondary school students who are taking their first steps in programming to the more specialised scientific engineers. And, now, us too!

And so , Jupyter Notebooks are used in academic environments (UC Berkeley, Stanford, UW, NYU, Cal Poly etc.), public sector investigations (NASA, JPL, KBase), and also in the private sector (IBM, Facebook, Microsoft, Bloomberg, JP Morgan, WhatsApp, Quantopain, GraphLab, Enthought, etc.) In terms of an architect of open modules, they’re are widely used to create all types of solutions and services, equally in commerce and non-profit.

How do we access it?

We can use it remotely or locally. From their own web page of the project, we can choose to try in in our browser, or install it locally ´install notebook´. Also, you can directly install it using the installation tool included in the package of Python pip.  Even so, the simplest way of installing it (in fact, what we have used ourselves in the previous post), is with Anaconda.
Página web del proyecto. Podemos probarlo desde el browser o instalarlo en local.
Figure 2: Project web page. We can try it from the browser or install it locally.
Thus we now have everything ready to start using this new working environment that is revolutionising the wat we work in the world of data.

Accessing the environment.

In the previous post, we installed Anaconda. If everything worked correctly, we can now open Jupyter Notebook directly from the Windows menu:
 Acceso desde el menú Windows.
Figure 3: Access from the Windows menu
It opens a command window that automatically launches the interface that is divided into 3 windows: ´Files´, ´Running´, and ´clusters´. By defect, it opens ´Files´ which I where we can create new notebooks or open an existing one.

Interfaz de Jupyter.
Figure 4: Jupyter Interface

We create a notebook and name it.

To create a notebook, we don’t need to do anything more than select the option ´New´ that appears in the top right corner.
Desde el menú New creamos un nuevo notebook Python.
Figure 5: From the menu”New” we create a new Python notebook.
Once we have created it, we give it a name by clicking on ´Untitled´.

Se crea como "untitled".
Figure 6: It´s created as ´Untitled´

We can call it  MyFirstNotebookPython  (or whatever we like!).

Renombramos el notebook.
Figure 7: We re-name the notebook.
Now we can see, at the end of the list, our new notebook. We can also see its status ´Running´.
Al final de la lista aparece el nuevo notebook.
Figure 8: The new notebook appears at the end of the list
We open it by simply clicking on the name and we see that it consists of a series of cells in which we can directly write the code. By clicking in the cell, we observe the change in colour of the border from blue to green. This means that we change from command mode (blue) to edit mode (green). To change back is as easy as clicking inside the cell or clicking escape.
Celda en modo comando (azul).
Figure 9: Command mode cell (blue).
Once in edit mode, we can start to write the commands that we would like. You can try this with one that you have used in the previous tutorial post, or with something simple like this. Write:

  print (“loquetúquieras”)
Probamos con el comando print.
Figure 10: We try the print command.
To carry out the code, you can choose the option ´Run cells´ in the ´Cell´ menu, or press ´Ctrl+Enter´– the result appears just below:
Resultado de ejecución de la celda.
Figure 11: Result of carrying out the cell

Creating a “Checkpoint”

Another of the most interesting functionalities of Jupyter Notebook is that it gives you the chance to create ´checkpoints´ or points of reference. When creating a checkpoint what you do in reality is save the status of the notebook in the exact moment so that you can return to this exact point and undo the changes that have been made after. This, evidently, is very interesting when you are doing tests or if something doesn’t turn out well. You can return without problems to the point where all was right without the need to start again from the beginning.

To create a checkpoint, you only need to select the option ´Save and Checkpoint´ from the ´File´ menu. To return to a previous checkpoint, you just have to select what you want from the menu ´File/revert to checkpoint´. 

Cómo volver a un checkpoint anterior.
Figure 12: How to get back to the previous checkpoint

Exporting a Notebook

Finally, to export a notebook, you must select the option that interests you the most from the menu ´File/ download as´. You can select from the formats notebook (ipynb), python (py), html, markdown, latex, pdf etc.

In the next post we will talk about the libraries and we will finish preparing the environment for our experiment of Machine Learning. Until them, we recommend you explore the help menus in Jupyter Notebooks and test out some of the simple commands to start getting to know the environment a little. In this video by CodingtheSmartWay you will find some examples to practice with.

Leave a Reply

Your email address will not be published.