Introduction to Jupyter Notebooks

Now that Anaconda is installed on your computer we will spend some time learning about the Jupyter notebook environment before experimenting with Python.The name Jupyter is derived from the names of the three most popular scientific computing languages that are supported by the notebook environment: Julia, Python, and R.

The Jupyter notebook has become one of the most popular means of performing, and sharing, scientific research and interactive computing. Some of the reasons to use Jupyter Notebooks are:

  • A single document for everything: Jupyter notebooks support the ingteractive development and execution of code, markdown documentation, graphs and figures, mathematical equations, maps, and much, much more all in a web-based environment served locally from your computer.
  • Reproducible work: The combination of markdown language with the ease of use Jupyter notebook makes documentation of your work simple.
  • Easy to share and convert: Since the notebooks are JSON documents, and since they can be easy converted to HTML and PDF with nbconvert. They can also be viewed by others without the Jupyter ecosystem in a web browser using nbviewer.

There are more reasons to use Jupyter notebooks, but these are the primary ones for those switching over from Excel or another spreadsheet program. These qualities will help you win your organization over to using notebooks to collaborate, share, and peer review projects.

Starting Jupyter Notebooks with IPython 3

The easiest way to start Jupyter Notebooks and the IPython environment is to open up a Command Prompt or Terminal window on your computer and and navigate to the directory where you want to work. Once there, type:

Jupyter notebook

Screen Shot 2018-04-13 at 9.52.53 PM

The Jupyter application will open in a web browser with the following address: http://loccalhost:888 meaning you are serving an instance locally on your computer. You will see a webpage that contains the directory and file structure where you opened the notebook. You can choose a directory here or you click on the “New” dropdown and select Python 3 to start an Python instance in a new tab.

Screen Shot 2018-04-13 at 9.53.15 PM

A new tab will appear with a single, empty cell. This is where we will type our markdown text or type and execute our code.

Screen Shot 2018-04-13 at 9.53.40 PM

Cells

Cells are where you will perform your work. There are two types of cells:

  • Code cells – contains code to be executed in with output printed below the cell.
  • Markdown cells – contain text formatted with Markdown for comments and any writing you choose to do.

To see how a code cell works, type:

print(‘Welcome to Jupyter Notebooks!)

Screen Shot 2018-04-13 at 11.14.37 PM

and press either Shift+Enter or Control+Enter. Alternatively, to run the cell you can click on the Run button at the top of the screen. I recommend taking the time to learn the keyboard shortcuts. They help you continue your workflow, making our typing and production quicker and more efficient. To help get you started, here is a list of common keyboard shortcuts.

Jupyter Keyboard Shortcuts (Command Mode)

  • Run a cell                                                                    Ctrl + Enter or Shift + Enter
  • Toggle between edit and command mode           Esc or Enter
  • Scroll up and down                                                   Up or Down keys
  • New cell above                                                           A
  • New cell below                                                           B
  • Activate Markdown cell                                           M
  • Activate Code cell                                                       Y
  • Delete active cell                                                        D 2x
  • Undo deleted cell                                                       Z
  • Select multiple cells                                                  Shift + Up or Down
  • Merge cells                                                                  Shift + M
  • Split cell                                                                       Ctrl + Shift + -

To see more features and their keystrokes type Ctrl + Shift + P while in command mode.

To quite, just click the Logout button in the top right corner of the screen.

This is enough to get you going. In future posts we will learn some basic Python commands and will take a look at Markdown.

Was this helpful for you? Please comment below for find me on Twitter to let me know.