A quick tour of Jupyter (aka IPython) Notebook

You can start this Jupyter (aka IPython) notebook from a terminal by running

jupyter notebook --pylab inline

The --pylab inline is for plotting graphs

First, we need to explain how to run cells. Try to run the cell below!


In [ ]:
import pandas as pd

print "Hi! This is a cell. Press the ▶ button above to run it"

You can also run a cell with Ctrl+Enter or Shift+Enter. Experiment a bit with that.

One of the most useful things about Jupyter notebook is its tab completion.

Try this: click just after read_csv( in the cell below and press tab, slowly


In [ ]:
pd.read_csv(

This is pretty useful, right?.

Okay, let's try tab completion for function names!


In [ ]:
pd.r

You should see this:

Writing code

Writing code in the notebook is pretty normal.


In [3]:
def print_10_nums():
    for i in range(10):
        print i,

In [4]:
print_10_nums()


0 1 2 3 4 5 6 7 8 9

Magic functions

Jupyter (aka IPython) has all kinds of magic functions. Here's an example of comparing sum() with a list comprehension to a generator comprehension using the %time magic.


In [12]:
%time sum([x for x in range(100000)])


CPU times: user 15.7 ms, sys: 2.76 ms, total: 18.4 ms
Wall time: 17.9 ms
Out[12]:
4999950000

In [13]:
%time sum(x for x in xrange(100000))


CPU times: user 9.45 ms, sys: 2.2 ms, total: 11.6 ms
Wall time: 11.8 ms
Out[13]:
4999950000

The magics I use most are %time and %prun for profiling. You can run %magic to get a list of all of them, and %quickref for a reference sheet.


In [14]:
%quickref

You can also do nutty things like run Perl code in the notebook with cell magics. This is especially cool for things like Cython code, where you can try out Cython really fast with the %%cython magic (you'll need to install it).


In [15]:
%%perl

$_ = "whoa, python!";
s/python/perl/;
print


whoa, perl!

That's it for now!