Jupyter Notebook Tutorial – A Guide for Data ScientistsAugust 31, 2020 2021-10-04 8:19
Jupyter Notebook Tutorial – A Guide for Data Scientists
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 Jupyter Notebook tutorial 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.
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.
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.
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.
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!
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.
Now, press Run from the Jupyter Notebook toolbar.
You can also create a Markdown cell where you can write text as a Markdown. Just select ‘Markdown’ from the Jupyter Notebook toolbar.
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.’
Then, again press on Run.
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 is 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:
|Shift + Enter||Run the current cell|
|Ctrl + Enter||Run selected cells|
|a||Insert cell above|
|b||Insert cell below|
|c||Copy selected cell|
|x||Cut selected cell|
|v||Paste copied/cut cell|
|Shift + m||Merge selected cells|
|m||Change cell to Markdown|
|y||Change cell to Code|
|z||Undo 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:
|Tab||Code completion or indent|
|Shift + Tab||Tooltip|
|Ctrl + d||Delete the whole line|
|Ctrl + /||Comment|
|Ctrl + a||Select 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.
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.
- 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.
- 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.
- You can add new extensions to give Jupyter Notebooks more functionality. Here is a good tutorial on how to do so: Enabling Jupyter Notebook extensions.
You are now equipped with the fundamental knowledge for working with Jupyter Notebook through this Jupyter Notebook tutorial. 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.
You can also learn about how to use Git for Data Science.
Are you interested in working with data? Get a free trial month of LinkedIn Learning and learn Data Science and Machine Learning courses using Python, R, and SQL from top instructors.
Enroll in any one of the courses from the following fields today on LinkedIn Learning and start your free month of learning:
Disclaimer: When you subscribe to LinkedIn Learning, we may earn a small commission as an affiliate. We love the platform so much so that we have been using it ourselves at The Click Reader.