IPython Notebook: An Overview

Me?

  • Ben Zaitlen
  • @quasiben
  • Developer and Data Scientist at Continuum Analytics

An Overview

  • What is it?
  • Basic Usage
  • Magics and Bangs
  • Multi-lingual Support
  • Hosted IPython Notebooks
  • IPCluster
  • Diabetes and Data

"The IPython Notebook is a web-based interactive computational environment where you can combine code execution, text, mathematics, plots and rich media into a single document"

  • More than an IDE
  • Programmers and people who program
  • Integrated visualization and processing
  • Storying telling with Data

Starting IPython/IPython Notebook

Extremely Easy Method:

  • Download Anaconda
  • $ipython or $ipython notebook

Can also be installed via pip and building from master

The Cell

In []:

Cell Types

  • Code
  • Markdown
  • Raw
  • Heading
In [1]:
1+1
Out[1]:
2
In [2]:
%pylab inline 
#(import numpy as np and matplotlib)
plt.xkcd()
x = np.arange(0,2*np.pi,.01)
plt.plot(x,np.sin(x))
Populating the interactive namespace from numpy and matplotlib

Out[2]:
[<matplotlib.lines.Line2D at 0x105f639d0>]

Execute a cell with:

  • shift+enter
  • ctrl+enter

Cells Run arbitrary Python Code...

And HTML

In [3]:
from IPython.display import HTML
s = """<marquee>DFW Pythoneers!!!</marquee>"""
h = HTML(s); h
Out[3]:
DFW Pythoneers!!!
In [4]:
%%HTML
<button type="button" id="loading-example-btn" data-loading-text="Loading..." class="btn btn-primary">
  Loading state
</button>

And JS

In [5]:
%%javascript
console.log('hello world');
<IPython.core.display.Javascript at 0x105f51810>
  • bootstrap
  • jquery
  • codemirror
  • and a few other goodies

Bokeh Plotting Library

  • New plotting library for interactive visualization
  • Plots embed Javascript (BokehJS) and some CSS
  • Callable through Python!
In [6]:
import bokeh.plotting as bplt
bplt.output_notebook()
bplt.figure()
bplt.line(x, sin(x), color="red")
bplt.show()
Bokeh Plot

Configuring embedded BokehJS mode.

Bokeh Plot
Plots

Or A full page on an external site!

In [7]:
from IPython.display import HTML
HTML('<iframe src=http://fiddle.jshell.net/bokeh/K8P4P/show/ width=600 height=700></iframe>')
Out[7]:

Inline Audio and Video

In [8]:
import numpy as np
from IPython.display import Audio
framerate = 44100
t = np.linspace(0,5,framerate*5)
data = np.sin(2*np.pi*220*t**2)
Audio(data,rate=framerate)
Out[8]: