Basic Anatomy of a Notebook and General Guide

  • Note this a is Python 3-flavored Jupyter notebook

My Disclaimers:

  1. Notebooks are no substitute for an IDE for developing apps.
  • Notebooks are not suitable for debugging code (yet).
  • They are no substitute for publication quality publishing, however they are very useful for interactive blogging
  • My main use of notebooks are for interactive teaching mostly and as a playground for some code that I might like to share at some point (I can add useful and pretty markup text, pics, videos, etc).
  • I'm a fan also because github render's ipynb files nicely (even better than r-markdown for some reason).

In this figure are a few labels of notebook parts I will refer to

OK, change this cell to markdown to see some examples (you'll recognize this if you speak markdown)

This will be Heading1

  1. first thing
  • second thing
  • third thing

A horizontal rule:


Indented text

Code snippet:

import numpy as np
a2d = np.random.randn(100).reshape(10, 10)

LaTeX inline equation:

$\Delta =\sum_{i=1}^N w_i (x_i - \bar{x})^2$

LaTeX table:

First Header Second Header
Content Cell Content Cell
Content Cell Content Cell

HTML:

Shortcuts!!!

  • A complete list is here, but these are my favorites:
Mode What Shortcut
Command (Press Esc to enter) Run cell Shift-Enter
Command Add cell below B
Command Add cell above A
Command Delete a cell d-d
Command Go into edit mode Enter
Edit (Press Enter to enable) Indent Clrl-]
Edit Unindent Ctrl-[
Edit Comment section Ctrl-/

Try some below


In [ ]:

As you can see on your jupyter homepage, you can open up any notebook

NB: You can return to the homepage by clicking the Jupyter icon in the very upper left corner at any time

You can also Upload a notebook (button on upper right)

As well as start a new notebook with a specific kernel (button to the right of Upload)

So, what's that number after In or Out? That's the order of running this cell relative to other cells (useful for keeping track of what order cells have been run). When you save this notebook that number along with any output shown will also be saved. To reset a notebook go to Cell -> All Output -> Clear and then Save it.

You can do something like this to render a publicly available notebook on github statically (this I do as a backup for presentations and course stuff):

http://nbviewer.jupyter.org/github/<username>/<repo name>/blob/master/<notebook name>.ipynb

like:
http://nbviewer.jupyter.org/github/michhar/rpy2_sample_notebooks/blob/master/TestingRpy2.ipynb


Also, you can upload or start a new interactive, free notebook by going here:
https://tmpnb.org



Also, if you are a MSFTE ask me about some other options not in GA yet (sorry public...).

The nifty thing about Jupyter notebooks (and the .ipynb files which you can download and upload) is that you can share these. They are just written in JSON language. I put them up in places like GitHub and point people in that direction.

Some people (like this guy who misses the point I think) really dislike notebooks, but they are really good for what they are good at - sharing code ideas plus neat notes and stuff in dev, teaching interactively, even chaining languages together in a polyglot style. And doing all of this on github works really well (as long as you remember to always clear your output before checking in - version control can get a bit crazy otherwise).

Some additional features

  • tab completion
  • function introspection
  • help

In [ ]:
?sum()

In [ ]:
import json
?json

The MIT License (MIT)
Copyright (c) 2016 Micheleen Harris


In [ ]: