How to Code in Python using Jupyter
The Jupyter Notebook is an open-source web application that you can use to create and share documents that contain live code, equations, visualization, and text.
The Jupyter was originally developed as a part of the Ipython project, which was used to provide interactive online access to python. Gradually it becomes useful to interact with other data analytic tools such as R.
The name Jupyter is derived from the combination of ‘Julia’, ‘Python’, ‘R’. As Jupyter runs good in many programming languages but python is a requirement for installing Jupyter Notebook.
There are a few ways through which you can download Jupiter. You can directly download jupyter from its official site.
However, in jupyter’s official website, it is recommended to install jupyter notebook using anaconda distribution which includes python, Jupiter, and other packages for scientific computing.
This also allows you to launch applications and manage Anaconda packages, environments. All we need to do is install Anaconda. You can download it.
After installing anaconda you can start jupyter notebook by using the following command in Anaconda prompt.
This will startup Jupyter and your default browser should start to follow. After you launch jupyter notebook the first page that will encounter is the notebook dashboard.
The dashboard of jupyter notebook will contain the following tabs :
The files tab displays files and folders under the current directory. It also displays the upload button using which a file can be uploaded to notebook server.
The running tab shows which of the notebook are currently running.
The cluster tab is provided by the Ipython parallel. Ipython’s parallel computing framework an extended version of Ipython kernel.
To create a new notebook, click on the New button in the upper right and select a kernel from the dropdown. The kernels listed depend on what’s installed on the server. Some of the kernels in the picture below may not exist as an option.
For simplicity let’s choose python 3.
Now your webpage should look like this.
You will notice that at the top of the page is the word untitled. This is the title for the page and the name of your notebook. You can change it by clicking on the word untitled and rename it.
Below it there is menubar. Each menu contains many options:
- New notebook: Choose the kernel to start a new notebook.
- Open: Takes the user to the dashboard to choose the notebook to open
- Save as: save current notebook and start a new kernel
- Rename: Renames notebook
- Save: Saves notebook
- Revert: Reverts state of notebooks to an earlier checkpoint
- Download: Export notebook in various file formats.
Edit menu consist of buttons cut, copy and paste cells, delete selected cells, split and merge cells, move cells up & down, find & replace within a notebook.
Buttons in this menu help to hide/display the header, toolbar, and cell numbers.
This menu gives you options for inserting cells before or after the current cell.
The options in this menu let users run all or specific cells in the notebook. You can also set the cell type to code, markdown, or raw nbconvert.
From this menu you can start, interrupt, restart, or shutdown the kernel. You can also start a new kernel.
From this menu you can save, clear, download, or embed widget state.
Various predefined keyboard shortcuts are displayed from this menu. You can also edit the shortcuts as per your convenience.
Cells in the jupyter notebook are of three types.
Contents in this cell are treated as a statement in the programming language of the current kernel.
This cell contains text formatted using markdown language. All kinds of formatting features are available like making text bold & italic, displaying order, or unordered list.
Contents in these cells are not evaluated by notebook kernel.
If you started with python 3 as your kernel, that means you can write python code in your code cells.
For running cells you can click on the Run button or just press Shift + Enter.
When you will run the cell output will be displayed under the code.