Thursday, August 16, 2018

(Python) Jupyter Notebook

In a previous entry, we discussed the Python Anaconda distribution and the Spyder IDE. In this article, we will be discussing a different IDE known as Jupyter Notebook. Jupyter Notebook can be utilized through the Anaconda platform as it is installed as an embedded aspect of such.

Jupyter Notebook’s capabilities are especially adept as it relates to the creation of Python programs which are specifically created for data science purposes. The reason for such, is like R-Studio, Jupyter Notebook allows for the creation and long term storage of data variables. This differs from the capabilities of Spyder, and other IDEs, which release variables from memory at the point of a program’s termination. Jupyter Notebook also enables, as a consequence of such, the ability to run separate portions of a program within the IDE. This is incredibly useful as it pertains to data projects, as there are often meddlesome aspects of data frames which require re-assessment.

To begin using Jupyter Notebook, you must first launch the Anaconda platform, this can be achieved by double clicking on the Anaconda desktop shortcut:


Once the initial Anaconda interface has loaded, to initiate the Jupyter Notebook IDE, click on the “Launch” button located below the option associated with Jupyter Notebook.


If your previous efforts were successful, a new tab should be opened within the default web browser. It is important that you remember to not accidentally close this tab when multi-tasking, or you will lose all of the work which was un-saved until that point.

At the initial screen, you must select the directory in which you wish to operate within. Also, from this menu, you have the ability to select files to load for further editing.


In our case, we will be creating a new file. To achieve this, we will first click the right button labeled: “New”. This will generate a drop-down menu, from which, we will select: “Notebook: Python 3”.


In the graphic below, I have already typed and executed a small block of code.


Each “ln []:”, represents a space for input, which, when ran, will execute the entirety of the code contained therein. Variables which are stored in this manner will remain as such. However, when the IDE session is terminated, the variables which were created during the session will be lost. Output is generated beneath each “ln[]:” space.

The rest of the platform is rather self-explanatory. The disk icon saves the session file, the cross icon adds additional “ln[]s”, and the menu bar enables various archaic options.


To change the title of the file, double click on the current file's title, this title is located to the right of the “Jupyter” logo. Doing such generates the screen above, which enables the process to be completed.

Finally, you will likely want to save your data. While clicking on the disk icon accomplishes this function, I would recommend utilizing the drop down file menu instead. From this menu, you can select the desired type of file format that you wish to utilize. I would recommend (downloading) saving files within both the Notebook (.ipynb) and Python (.py) file formats. The former allows for a greater ease of editing within the Jupyter platform, and the latter allows your file to be read across Python platforms regardless of the IDE.


In the next article, we will continue our journey through Python programming. Thanks for subscribing, and stay tuned!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.