A motivating example...
from __future__ import division, print_function
import numpy as np
import pandas as pd
!ls
881.png Section3_bokeh.ipynb heat_3-2.png AAPL.hdf5 Section4_vtk.ipynb interestingBugs.jpg GOOG.hdf5 Section4_vtk.py iris.csv README.md Untitled0.ipynb python.png SaintHelens.vtk goog_fit.png selection.png Section0_intro.ipynb heat_1-1.png smooth_kernel.png Section1-1_ipython.ipynb heat_1-2.png smooth_power.png Section1-2_matplotlib-Live.ipynb heat_2-1.png smooth_signal.png Section1-2_matplotlib.ipynb heat_2-2.png Section2_numpy_scipy_pandas.ipynb heat_3-1.png
iris = pd.read_csv("iris.csv")
iris.columns
Index([u'Unnamed: 0', u'SepalLength', u'SepalWidth', u'PetalLength', u'PetalWidth', u'Species'], dtype='object')
#iris['SepalLength'].head()
iris.SepalLength.head()
0 5.1 1 4.9 2 4.7 3 4.6 4 5.0 Name: SepalLength, dtype: float64
iris.head()
Unnamed: 0 | SepalLength | SepalWidth | PetalLength | PetalWidth | Species | |
---|---|---|---|---|---|---|
0 | 1 | 5.1 | 3.5 | 1.4 | 0.2 | setosa |
1 | 2 | 4.9 | 3.0 | 1.4 | 0.2 | setosa |
2 | 3 | 4.7 | 3.2 | 1.3 | 0.2 | setosa |
3 | 4 | 4.6 | 3.1 | 1.5 | 0.2 | setosa |
4 | 5 | 5.0 | 3.6 | 1.4 | 0.2 | setosa |
import matplotlib.pyplot as plt
%matplotlib inline
plt.scatter(iris.PetalLength, iris.PetalWidth)
plt.scatter(iris['PetalLength'], iris['PetalWidth'], c=iris['Species'].factorize()[0])
<matplotlib.collections.PathCollection at 0x106c6f4d0>
IPython notebook uses a client/server application. It can be accessed remotely if it lives on a accessible server. However, it is commonly used through localhost.
ipython notebook
(default port is 8888, specify a port with --port
)You can create multiple notebooks in one directory. You can have multiple servers running at once (different port numbers). I tend to start a server for each project in a directory convenient to the project data.
Press 'h' in command mode to get a list of keyboard shortcuts
File -> Download as
to get a static copyCell
menu has lots of execution optionsHelp
has handy links to python, markdown and common library's documentation??iris
?iris
%pdoc iris
!ls
881.png Section3_bokeh.ipynb heat_3-2.png AAPL.hdf5 Section4_vtk.ipynb interestingBugs.jpg GOOG.hdf5 Section4_vtk.py iris.csv README.md Untitled0.ipynb python.png SaintHelens.vtk goog_fit.png selection.png Section0_intro.ipynb heat_1-1.png smooth_kernel.png Section1-1_ipython.ipynb heat_1-2.png smooth_power.png Section1-2_matplotlib-Live.ipynb heat_2-1.png smooth_signal.png Section1-2_matplotlib.ipynb heat_2-2.png Section2_numpy_scipy_pandas.ipynb heat_3-1.png
files = _
files2 = !ls
print(files2)
['881.png', 'AAPL.hdf5', 'GOOG.hdf5', 'README.md', 'SaintHelens.vtk', 'Section0_intro.ipynb', 'Section1-1_ipython.ipynb', 'Section1-2_matplotlib-Live.ipynb', 'Section1-2_matplotlib.ipynb', 'Section2_numpy_scipy_pandas.ipynb', 'Section3_bokeh.ipynb', 'Section4_vtk.ipynb', 'Section4_vtk.py', 'Untitled0.ipynb', 'goog_fit.png', 'heat_1-1.png', 'heat_1-2.png', 'heat_2-1.png', 'heat_2-2.png', 'heat_3-1.png', 'heat_3-2.png', 'interestingBugs.jpg', 'iris.csv', 'python.png', 'selection.png', 'smooth_kernel.png', 'smooth_power.png', 'smooth_signal.png']
%prun print(100)
100
from IPython.display import display
from IPython.display import Image
display(Image(filename='interestingBugs.jpg'))
And an honorable mention