Thanks to

Jupyter Notebook Tutorial – A Guide for Data Scientists

Jupyter Notebook Tutorial

Jupyter Notebook Tutorial – A Guide for Data Scientists

Jupyter Notebooks have become the go-to IDE for a lot of data science aspirants and yet, a lot of professionals (including data scientists) still struggle to use it for their day-to-day work.

This tutorial on getting started with Jupyter Notebook aims to help you see the big picture of what you can do with Jupyter Notebooks and hopefully, empower you to maximize your efficiency as a Data Scientist.

What is a Jupyter Notebook?

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. 

Project Jupyter

Jupyter Logo

Jupyter Notebook is an interactive IDE that supports over 40 different programming languages including Python, R, Julia, and Scala. It also allows the use of mark-downs to help data scientists quickly jot down ideas and document results.

One of the best things about Jupyter Notebooks is its minimalistic design and user interface – even a non-programming professional can understand the contents of the notebook based on the content of the markdown. Also, since the Notebook can be hosted on different platforms, it has become a medium to show the capability of what a job-seeking data scientist can do.

Installing Jupyter Notebook for Python

Installing the Jupyter Notebook is pretty easy in Python with the pip package installer. Just open your terminal and write the following command:

pip install notebook

Alternatively, if you’re using the conda package manager, you can install jupyter notebook with the following command:

conda install -c conda-forge notebook

Once the installation finishes, you can start your Jupyter Notebook by just writing jupyter notebook in the terminal as follows.

jupyter notebook

Now you can access the Jupyter Notebook from your browser by going to http://localhost:8888/. The port number may be different on your system so make sure to look at your terminal to find the right URL.

Jupyter Notebook Tutorial - A Guide for Data Scientists

Tip to remember: Make sure to change your directory to the desired location before starting the Jupyter notebook so that you can properly manage your notebooks.

Creating your first notebook

Let us start this Jupyter Notebook tutorial by creating your first notebook. Go to the top-right of your Jupyter Notebook window and click on New.

Creating your first notebook in Jupyter Notebook

Select the available Python version and a new iPython notebook will be created with the extension .ipynb. Now, you’re all ready to start coding!

Jupyter Notebook User Interface

As you can see, iPython notebooks on Jupyter Notebooks are based on a cell format, that is, you can write Python code in cell blocks and execute it then and there.

Let us write a simple ‘Hello, World!’ format to demonstrate that by writing some Python code in the cell.

print("Hello, World!")

Now, press Run from the Jupyter Notebook toolbar.

Hello World program in Jupyter Notebook

You can also create a Markdown cell where you can write text as a Markdown. Just select ‘Markdown’ from the Jupyter Notebook toolbar.

Change cell to Markdown in Jupyter Notebook - 1

Notice how the In [ ] symbol disappears from the side of the cell. Markdown texts are useful in writing essential guidelines and comments for the code. Let’s try writing, ‘This is a Markdown text.’

Change cell to Markdown in Jupyter Notebook - 2

Then, again press on Run.

Change cell to Markdown in Jupyter Notebook - 3

There you have it! You’ve written your first line of code as well as your first Markdown text in Jupyter Notebook. Quite neat, isn’t it?

Shortcut commands for Jupyter Notebook

Now that you’re familiar with the basics of Jupyter Notebook, it might be a good idea to remember some shortcuts so that you don’t have to go to the toolbar over and over again to run a cell or to perform other similar operations.

Here a list of commonly used shortcut commands as well as the respective operations they perform in Jupyter Notebook.

a. Command Mode – You can go to the ‘Command Mode’ by clicking inside a cell and then, pressing the escape (Esc) key on your keyboard. Once, you are in Command mode, you can use the following shortcut commands:

Shortcut CommandOperation
Shift + EnterRun the current cell
Ctrl + EnterRun selected cells
aInsert cell above
bInsert cell below
cCopy selected cell
xCut selected cell
vPaste copied/cut cell
Shift + mMerge selected cells
mChange cell to Markdown
yChange cell to Code
zUndo cell operation

b. Edit Mode – You can go to the ‘Edit Mode’ by selecting a cell and pressing the Enter key on your keyboard. Once, you are in Edit Mode, you can use the following shortcut commands:

Shortcut CommandOperation
TabCode completion or indent
Shift + TabTooltip
Ctrl + dDelete the whole line
Ctrl + /Comment
Ctrl + aSelect all content of the cell
Ctrl + Shift + Minus (-)Split cell at the current cursor position

These are only some of the shortcut commands available to you. If you want to learn more shortcut commands, click Help on the toolbar and press on Keyboard Shortcuts.

Shortcut commands for Jupyter Notebook

You can also edit your keyboard shortcuts however it isn’t necessary.

Some Jupyter Notebook tips and tricks

Let us have a look at some neat tips and tricks that you can do in Jupyter Notebook.

  • You can run terminal commands using an exclamation sign (!) at the beginning of the Code cell.
Exclamation mark in Jupyter Notebook
  • You can read the in-notebook documentation of various functions using a question mark (?) sign at the end of your function and running the cell.
Question mark in Jupyter Notebook
  • You can interrupt the kernel, restart it as well as run all of the cells from the top of the notebook. Just go to the toolbar and press on Kernel to perform these operations.
Kernel options in Jupyter Notebook

In Conclusion

You are now equipped with the fundamental knowledge for working with Jupyter Notebook. Although this tutorial doesn’t cover all of the different tips and tricks (since there are many), we still hope it was helpful to you. If you feel something is missing or if you’re stuck, feel free to write it down in the comments below.

Also, as a reward for sticking to the end of this article, here’s a free mini-course for you on ‘Practical Data Science – A Guide For New-Age Business Owners’.

And, if you are interested, we have also launched a free Data Science Specialization track with Python for data science aspirants like you. In the specialization track, you will learn the fundamentals of Python and then later delve into advanced topics such as Machine Learning (and Deep Learning) using TensorFlow 2.0.

The best part is – you don’t have to study alone! You can join our vibrant community of data science aspirants who are there to help you in your learning journey: Join the TCR community. See you on the course!

Leave your thought here

Your email address will not be published. Required fields are marked *