Jupyter Notebook for Beginners
Jupyter Notebook is an extremely powerful and useful tool for developing data analytics projects interactively.
In the previous lesson, you learned how to install Anaconda on your computer. This lesson will walk you through how to use Jupyter Notebook for data science projects.
As I mentioned, a notebook (Jupyter Notebook) helps you combine code and its output along with markdown texts, math equations, visualizations, and other rich media into a single document. In other words, in a notebook, you can write and execute code in an interactive way, add explanations using markdown texts, and use formulas, plots, and other visual elements to make your work more comprehensive and shareable. These features help you speed up developing data science projects and make communicating and sharing your results easier.
Now let’s see how we can use Jupyter Notebook and write Python code into it.
Opening Jupyter Notebook
Jupyter Notebook can be opened through, first, the Anaconda Navigator and second, the command line or terminal. In the previous lesson, I showed you how to open Anaconda Navigator. In this lesson, I will show you how you can use the terminal to open Jupyter Notebook and create your notebooks.
Step 1: First, open a terminal or (cmd on Windows machines), create the python_for_analytics
folder on your computer’s desktop, then use the following command to enter this directory.
$ cd
desktop/python_for_analytics
Step 2: In this step, just type, then Jupyter Notebook will be open in your web browser.
$ jupyetr notebook
With Jupyter Notebook open in your browser, you may have noticed that the URL for the dashboard is something like https://localhost:8888/tree
. Localhost indicates that the content is being served from your local machine, which means your own computer.
Jupyter Notebook is a web application, and this feature makes it platform-independent.
Creating a Python File
Creating a new notebook for writing Python code is as simple as clicking the New button on the right side of the Jupyter Notebook dashboard and then selecting Python 3.
Once you click the Python 3 button, a new browser tab will be opened, and you can see the following page. Also, it’s possible to change the notebook name by clicking on its name at the top of the page. Let’s name this notebook chapter_01.
Now that we’ve opened up Jupyter Notebook and created a file that we can work with,
let’s talk about cells.
In each cell, you can write code or markdown. Let’s start with the markdown.
- Click on the first cell, and then press
esc+M
on your keyboard. Now the type of the cell is changed to markdown. - Within the cell, write the following markdown text:
# Chapter 1
The number of hashtags at the beginning of the text will change the size of the heading, Like HTML
<h1>, <h2>, <h3>, or etc
tags.
- Now run the cell by pressing
shift+enter
on your keyboard.shift+enter
runs the current cell, and a new cell will appear below the current one.
In the new cell, write the following code:
print("Hello, Python for Analytics!")
Go ahead and run the cell. It will run the code within the cell and output the result.
You will learn a ton of new things about working with Jupyter Notebook and Markdown in this course.
Alright, I hope you enjoyed this lesson. In the following lessons, you will learn the fundamentals of Python programming.