Signup/Sign In

Beginners Guide to Jupyter Notebook

Posted in Programming   LAST UPDATED: SEPTEMBER 7, 2019

    In this tutorial, we will learn all about Jupyter notebook, starting from how to install it to using it for executing python code.

    As we all know, Jupyter notebook provides the most convenient way of writing code in python, and it especially fits best when working with machine learning algorithms. The visualization process is also done with so much ease in Jupyter notebooks. And how can we forget the markdown tab?

    Jupyter notebook also provides you support for special mathematical characters to represent complex mathematical equations too.

    But most importantly, the modules and packages that can be easily imported in the notebook and most of them come pre-installed, make it a cakewalk to write and execute code.

    Well, there are so many advantages of using the jupyter notebooks, but I've seen so many students struggling with it. Some might be used to using Jetbrains IDE, or some just didn't give enough time exploring jupyter notebook. Whatever the reason is, this article is going to make you comfortable with the 'iypnb' notebooks in no time.

    I am not going to cover the heavy kernel and other complex topics as they might scare you away. Just some basic stuff so that you can easily start using Jupyter notebook.

    So, let's get started.




    What is a Notebook?

    In layman terms,

    "A notebook is a combination of text, code, output, and visualization all under the same window".




    Why use Jupyter?

    Why are we using Jupyter and not Pycharm, Sublime text editor etc?

    Well, I am not going to lie but Jupyter is actually more easy to use and of course, Pycharm is a heavyweight software that might slow down your local machine(assuming you don't have a good gaming laptop). So Jupyter is a great choice which makes it easier for you to start practicing code in python, be it plotting graphs using matpotlib, or generating n-dimensional array using numpy, or using machine learning algorithms using scikit-learn module.




    How to download Jupyter?

    It's not a direct process, you have to download it using Anaconda. (recommended way)

    Don't worry it's not going to bite you. (*joking*)

    Anaconda is actually a data science platform. All the package depndencies for data science are well-taken care by the conda. If you install conda, you don't need to use pip install command for the packages.

    Not only jupyter, you get access to spyder, which is an IDE, also you get Rstudio and some other useful tools which you can view from Anaconda Navigator.

    So let's download the latest verion of Anaconda from here: https://www.anaconda.com

    You can also install jupyter using python Installer Package or pip command, but I would recommend that you use Anaconda.

    Once downloaded, install it with all the default options.

    Now, in the folder where Anaconda files are stored, you will have a Jupyter notebook icon. Right click and create shortcut on the desktop.

    You are all set for the magic now. Double click on the icon and a window similar to command prompt will appear. You can see some text automatically written on that window, we don't have to care about that. After a few seconds, a tab in your default browser will appear. Some folders on your local machine will be visible on that.

    Jupyter Notebook dashboard

    On the top right corner you will see the option New. Click on New -> Python 3.

    Create Jupyter Python project

    Your first python notebook is created now.

    On the left top corner, click on 'untitled' to rename the notebook, If I were you, I'd have written 'My first Notebook'. Click on 'Rename'.

    name jupyter notebook

    Done!

    Now the rectangular boxes you can see are called 'Cells'. You write your code here.

    Now it's your turn to write the code you want. Let me write one example for you, copy paste it in your notebook's cell and run.

    In the code below, we are importing the Numpy library which is already available in the Jupyter notebook, thanks to Anaconda. I don't have to install it.

    Use keyword import : import "Name_of_library".

    import numpy
    
    print(numpy.array([1,2,3,4,5]))

    See, how the output and input is on the same window and how beautiful and understandable it appears.

    All other options like 'Run', 'Save', 'Cut', 'Insert' and much more are at the top of the cells.

    Some useful and important shortcuts are:




    Keyboard Shortcuts

    1. Shift+Enter: Executes the code in the cell you are working on.

    2. Tab+Shift: When you are writing some in-built function and you want to know what are the arguments required? Which one among them are optional and compulsory? This shortcut will tell you the arguments required so that you don't have to remember them.

    3. Tab: Autocompletes the name of the function etc.

    1. esc+m: Changes cell type to markdown. What is a markdown cell? It's just the non-code cell which is used to write the theory and symbols. Also gives us extensive options for including heading, bold text, italic text and much more.




    Save and Checkpoint

    At last you can save your work, notebooks are autsaved after 120 seconds but you can save them too by either going to file-> save and checkpoint, or by using ctrl+s. Also, there is a save icon on the options pallet above the cells. The checkpoint is just a kind of GitHub commit which lets you go back to previous change if the notebook is accidentally closed or some mistyping happens. Just go to File -> Revert to Checkpoint option and you can easily undo the changes.

    So, now you have successfully installed Jupyter Notebook, created your first 'iypnb' notebook and written some code in it along with using great keyboard shortcuts.

    Thanks for reading! Don't forget to share.

    About the author:
    I am an undergraduate pursuing B.Tech Computer Science, currently in 3rd year.I love to manipulate data to make sense out of it, my interests include machine learning and deep learning.I love to code in python.
    Tags:PythonJupyter Notebook
    IF YOU LIKE IT, THEN SHARE IT
     

    RELATED POSTS