- This topic has 0 replies, 1 voice, and was last updated 9 months, 3 weeks ago by Oluwole.
- February 11, 2020 at 12:04 pm #85626Participant@oluwole
This article introduces you to the use of one of the more preferred user interface (UI) for data scientists – JupyterLab. From its installation to creating your first file, this guide walks you through the basics you need to get started working with JupyterLab. We’d start with a little background on what JupyterLab is, and then things will get more practical. So get your lab coats ready!
What is JupyterLab?
JupyterLab is a web-based interactive computational environment commonly used for data visualization and data analysis. It became the newest development for Project Jupyter after its beta release in 2018. It is, in many ways, an upgrade on the classic Jupyter Notebook which was released in 2011.
Project Jupyter exists to develop open-source software, open-standards, and services for interactive computing across dozens of programming languages.
Although the Jupyter Notebook has been largely successful with millions of users all over the world and support for over 100 programming languages, it has some shortcomings. One of such is the inability to use various software workflows with the notebook alone. JupyterLab provides a solution to this by enabling a high level of integration between activities, files, and notebooks.
Did you know that the name, Jupyter, comes from the core supported programming languages that it supports: Julia, Python, and R?
Some additional features of JupyterLab include:
- A modular structure in the similitude of an IDE
- A model for viewing and handling different data formats such as images, CSV, JSON, Markdown, PDF, Vega, Vega-Lite, etc.
- Flexible environment allowing for customization (docking, dynamic dashboard) and 3rd-party party extensions
- Integrated toolset offering a file browser, consoles, code/text editors, terminals, etc. on the same screen.
- JupyterLab puts most of the tools needed by data scientists into a single environment. It is sure to ease the Jupyter Notebook out of use.
If you have been using the Notebook, now is not a bad time to make a switch. If you’re a beginner, my advice is to get started with JupyterLab so you become familiar with it.
Let’s get it installed.
There are several methods of installing JupyterLab, but I’d recommend using either conda or pip. To do this, launch your command prompt as administrator and type in the following;
conda install -c conda-forge jupyterlab
pip install jupyterlab
It should take a few minutes, and you should ensure you have a strong and stable internet connection.
After a successful installation, Jupyterlab can be started by using the following code in your command prompt:
JupyterLab opens automatically in your default browser. It is currently supported by Firefox, Chrome, and Safari browsers.
Changing JupyterLab Start-up folder
You might notice that the start-up folder or directory has weird subfolders and files. To change the start-up folder, run this in your command prompt;
jupyter notebook --generate-config
This command writes a file to C:\Users\username\.jupyter\jupyter_notebook_config.py
Browse to the file location using your File Explorer and open the file in an editor.
Search for this line in the file (Ctrl + F):
#c.NotebookApp.notebook_dir = ''
Replace it by entering your desired start-up file path in-between the quotes:
c.NotebookApp.notebook_dir = "C:/Users/Wolemercy/OneDrive/Documents/Work/Data Science"
Ensure you remove the comment tag at the begging of the line, i.e., delete the # so the code can execute.
Save and close the file.
Restart Jupyter, and your startup directory should be as specified.
The JupyterLab Environment
Now that we’ve set up our Lab let’s explore the some of the features of the environment
The dashboard is located on the far left in the window. It comprises of 5 icons corresponding to the File Browser, Running Terminals & Kernels, Commands, Notebook Tools, and Open Tabs, in that order.
File Browser allows you to launch new notebooks, consoles, and terminals, as shown below. It also shows the current file path and allows for the creation of folders, file uploads and opening new launcher tabs.
Terminals & Kernels Sessions list all the currently active kernels and terminals. The kernels refer to the open notebooks and consoles while the terminal provides for a Windows Powershell command prompt.
Commands Centre contains a list of commands that allow for different operations within the lab. It features a Console panel, an extension manager, a Help panel, Notebook Cell Operations and Notebook Operations Settings, Theme settings and Terminal settings. Theme settings give you control of the display environment, allowing you to make changes to fonts, and switch between JupyterLab Dark and Light modes.
Clicking on the Open Tabs icon gives you a list of the currently open tabs in that window.
At the top of the window, we have the File, Edit, View, Run, Kernel, Tabs, Settings, and Help panels. The Run tab lets you specify how you want to run your cells while the Kernel tab helps you manage your kernels. The other panels have their usual meanings.
Creating Your First Notebook
We will now go on to create our first JupyterLab Notebook. There are many ways to do this, but this but here are the general steps;
Go to the File browser tab on the dashboard and click on the “+” icon to open a new launcher. On the Launcher window, under Notebook, click on Python 3 as shown below;
A new notebook named “Untitled.ipynb” is created. To rename it, right-click on the notebook in the file browser on the dashboard and click on “Rename.” Now enter the new name of the file, say “My first file.ipynb.”
You have now created your first JupyterLab Notebook
A cell here refers to a multiline text input field that can be executed by using Shift-Enter. These cells are where you’d be entering your codes. Let’s see how the cells work by creating a Pandas dataframe.
Running a Code Cell
A code cell is a type of cell that allows us to edit and write new code, formatted with full syntax highlighting. Each cell is by default a code cell. If otherwise, a cell can be converted to a code cell by using the keyboard shortcut Y or the cell menu.
First import the Pandas library using:
Import pandas as pd
Press Shift-Enter or use run to execute the command
The [*] located beside the cell indicates that the notebook is currently running that cell. After its successful completion, the [*] is replaced by , indicating that that is the first cell to be run in that notebook. The cell number increases as you run more code cells.
Running a Markdown Cell
You’ve just seen how to run a line of code in the notebook. What if you want to enter a text that should not be treated as a code? Those kinds of cells are referred to as Markdown Cells. They are useful for giving titles or headings to cell groups. A cell can be changed to a markdown cell by using the cell menu or the keyboard shortcut M. An important distinction between the Markdown and the Code cells is that the former has no cell number while the latter dows
Let’s see an example:
Creating an Array
Using the cell menu, select Markdown. Now use Shift-Enter to execute. It should look like this:
Let us finish creating the array by typing this code:12my_array = pd.array([2,4,6,8,10])my_array
To save or create a checkpoint, use Ctrl-S or the save icon on the panel.
There are many other cell features you should also explore, such as cutting, copying, pasting, and moving cells.
The console lets you execute commands and try out test codes without having to create a file or work within the notebook. To open a console, in the Launcher window, click on Python 3 under the Console Option. The console should open in a new window.
You can type in a command and use Shift-Enter to Execute. For example
print('Glory glory Man United')
Some other features of JupyterLab include;
- Customizing windows: Your windows can also be customized by dragging the tabs to any preferred position as shown below. This allows for a more dynamic view that suits your workflows.
- Opening other files: Text files, CSVs, spreadsheets, and even images can be opened with JupyterLab
Having installed JupyterLab, and explored some of its features, its ease of use is very apparent. And if you ever need any assistance, the Help option therein is sure to bail you out!
JupyterLab is a big upgrade on Jupyter Notebook with its more modular appearance and extensive features. For the data scientist, JupyterLab provides in a single environment; most of the tools he needs to be functional and competitive. It is indeed, a powerful tool.
- You must be logged in to reply to this topic.