I thought I had already shared this article, but somehow it was in my imagination (Also lying as a draft post). So here goes, this one should have been shared before we dived into seaborn. Anyways, as the traffic slogans says better late than never. 😀 so, lets start Beginning with Jupyter Notebook

Beginning with Jupyter Notebook
Taken from Jupyter official site, showing something of a workbook I guess.

What is Jypter Notebook?

It is your one-stop solution for sharing your experiments, codes and results anywhere on the web. Including, the most popular GitHub that allows live execution of the code ready to share. The official website of Jupyter describes the notebook as

“The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and narrative text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more.”

This tutorial will cover the following topics: 

  • A basic overview of the Jupyter Notebook App and its components,
  • An overview of the three most popular ways to run your notebooks: with the help of a Python distribution, with pip or in a Docker container,
  • A practical introduction to the components that were covered in the first section, complete with examples of Pandas DataFrames, an explanation on how to make your notebook documents magical, and answers to frequently asked questions, such as “How to toggle between Python 2 and 3?”, and
  • The best practices and tips that will help you to make your notebook an added value to any data science project!

beginning with Jupyter Notebook.

In this case, “documents” represents documents that contain both code and rich text elements, such as figures, links, equations, … Because of the mix of code and text elements, these documents are the ideal place to bring together an analysis description, and its results, as well as, they can be executed to perform real time data analysis.

“Jupyter” is a loose acronym meaning Julia, Python, and R. These programming languages were the first target languages of the Jupyter application, but nowadays, the notebook technology also supports many other languages

What Is The Jupyter Notebook App?

As a server-client application, the Jupyter Notebook App allows you to edit and run your notebooks via a web browser. The application can be executed on a PC without Internet access, or it can be installed on a remote server, where you can access it through the Internet.

Its two main components are the kernels and a dashboard.

A kernel is a program that runs the user’s code. The Jupyter Notebook App has a kernel for Python code, but there are also kernels available for other programming languages. So, how to actual beginning with Jupyter Notebook.

How To Install Jupyter Notebook

You might have guessed it by now that all applications are installed sameway in Python so the following command will do the trick

pip install jupyter

Running Jupyter Notebook

Docker is an excellent platform to run software in containers. These containers are self-contained and isolated processes.

This sounds a bit like a virtual machine, right?

Not really. Go here to read an explanation on why they are different, complete with a fantastic house metaphor.

Jupyter Notebook Tutorial - Docker

You can easily get started with Docker if you install the Docker Toolbox. It contains all the tools you need to get your containers up and running. Follow the installation instructions. Select the “Docker QuickStart Terminal” and indicate to install the Kitematic Visual Management tool too. If you don’t have it or any other virtualization platform installed. 

The installation through the Docker Quickstart Terminal can take some time, but then you’re good to go. Use the command docker run to run Docker “images”. You can consider these images as pre-packaged bundles of software. That can be automatically downloaded from the Docker Hub when you run them. 

Tip: browse the Docker Image Library for thousands of the most popular software tools. You will also find other notebooks that you can run in your Docker container. Such as the Data Science , the R, and many more.

To run the official Jupyter Notebook image in your Docker container, give in the following command in your Docker Quickstart Terminal:

docker run --rm -it -p 8888:8888 -v "$(pwd):/notebooks" jupyter/notebook 

Tip: if you want to download other images, such as the Data Science Notebook that has been mentioned above, you just have to replace the “Jupyter/notebook” bit by the Repository name you find in the Docker Image Library, such as “Jupyter/datascience-notebook“.

The newest Jupyter HTML Notebook image will be downloaded, and it will be started, or you can open the application. Continue to read to see how you can do that!

How To Use Jupyter

Now that you know what you’ll be working with and you have installed it, it’s time to get started for real!. Beginning with Jupyter Notebook

Run the following command to open up the application:

jupyter notebook

Then you’ll see the application opening in the web browser on the following address: http://localhost:8888.

Let’s start by making a new notebook.

You can easily do this by clicking on the “New button” in the “Files tab”. You see that you have the option to make a regular text file, a folder, and a terminal. Lastly, you will also see the option to make a Python 3 notebook.

You can immediately start with importing the necessary libraries for your code. This is one of the best practices that we will discuss in more detail later on.

After, you can add, remove or edit the cells according to your needs. And don’t forget to insert explanatory text or titles and subtitles to clarify your code! That’s what makes a notebook a notebook in the end. 

Interactive Notebooks As Dashboards: Widgets

To add widgets to your notebook, you need to import widgets from ipywidgets:

from ipywidgets import widgets

That’s enough to get started! You might want to think now of what type of widget you want to add. The basic types of widgets are text input, buttons, and input-based widgets.  

Share Your Jupyter Notebooks

In practice, you might want to share your notebooks with colleagues or friends to show them what you have been up to as a data science portfolio for future employers. However, the notebook documents are JSON documents that contain text, source code, rich media output, and metadata. Each segment of the document is stored in a cell.

Ideally, you don’t want to go around and share JSON files. 

That’s why you want to find and use other ways to share your notebook documents with others.

When you create a notebook, you will see a button in the menu bar that says “File”. When you click this, you see that Jupyter gives you the option to download your notebook.

You can use the nbconvert command to convert your notebook document file to another static format, such as HTML, PDF, LaTex, Markdown, reStructuredText, … But don’t forget to import nbconvert first if you don’t have it yet! 

Then, you can give in something like the following command to convert your notebooks: 

jupyter nbconvert --to html Untitled4.ipynb

With nbconvert, you can make sure that you can calculate an entire notebook non-interactively, saving it in place or to a variety of other formats. The fact that you can do this makes notebooks a powerful tool for ETL and for reporting. For reporting, you just make sure to schedule a run of the notebook every so many days, weeks or months;

So this completes our Beginning with Jupyter Notebook.