Dražen's humble introduction to
What's IPython notebook? A web interface for a scientific Python shell.
Started by Fernando Perez to bring modern, open source tools to the research community.
Main features:
a=range(5)
a
[0, 1, 2, 3, 4]
a.remove(3)
a.remove?
a
[0, 1, 2, 4]
def divide():
a = 1
b = 4
c = b / (a-1)
divide()
--------------------------------------------------------------------------- ZeroDivisionError Traceback (most recent call last) <ipython-input-5-a8416233c05c> in <module>() 4 c = b / (a-1) 5 ----> 6 divide() <ipython-input-5-a8416233c05c> in divide() 2 a = 1 3 b = 4 ----> 4 c = b / (a-1) 5 6 divide() ZeroDivisionError: integer division or modulo by zero
pwd
! open unpause_action.pdf
%magic
for some extra info)%timeit a*3
You can easily install it on your server to have a consistent environment
sudo apt-get install ipython
The ultimate lab notebook! Inside it you can use cool features such as:
Can you believe it? I used to code in Java!
private static int maxValue(char[] chars) {
int max = chars[0];
for (int ktr = 0; ktr < chars.length; ktr++) {
if (chars[ktr] > max) {
max = chars[ktr];
}
}
return max;
}
E=mc2≠∑i∈Nei+∫∞0e−xdx
from IPython.lib.display import YouTubeVideo
YouTubeVideo('HaS4NXxL5Qc')
x = linspace(0, 2*pi)
y = sin(x)
plot(x,y)
show()
Analysing time series data about wind farm power generation. (kaggle competition)
! head data/kaggle/wind_forecast/train.csv
date,wp1,wp2,wp3,wp4,wp5,wp6,wp7 2009070100,0.045,0.233,0.494,0.105,0.056,0.118,0.051 2009070101,0.085,0.249,0.257,0.105,0.066,0.066,0.051 2009070102,0.02,0.175,0.178,0.033,0.015,0.026,0 2009070103,0.06,0.085,0.109,0.022,0.01,0.013,0 2009070104,0.045,0.032,0.079,0.039,0.01,0,0 2009070105,0.035,0.011,0.099,0.066,0.015,0.013,0 2009070106,0.005,0,0.069,0.105,0.015,0.079,0 2009070107,0,0.011,0,0.017,0.025,0.013,0.025 2009070108,0,0.016,0,0.017,0.046,0,0
import pandas as pd
def format_timestamp(raw):
return '%s %s:00' % (raw[:-2], raw[-2:])
wind = pd.read_csv('data/kaggle/wind_forecast/train.csv', parse_dates=['date'], index_col=['date'], converters={'date':format_timestamp})
wind
<class 'pandas.core.frame.DataFrame'> DatetimeIndex: 18757 entries, 2009-07-01 00:00:00 to 2012-06-26 12:00:00 Data columns: wp1 18757 non-null values wp2 18757 non-null values wp3 18757 non-null values wp4 18757 non-null values wp5 18757 non-null values wp6 18757 non-null values wp7 18757 non-null values dtypes: float64(7)
wind.index
<class 'pandas.tseries.index.DatetimeIndex'> [2009-07-01 00:00:00, ..., 2012-06-26 12:00:00] Length: 18757, Freq: None, Timezone: None
a = '2009-07-01'
b = '2009-07-03'
wind[a:b].plot()
ylabel('normalized wind power')
<matplotlib.text.Text at 0x10ddab450>
wind['wp1'][a:b].plot(color='red', label='raw power')
pd.ewma(wind['wp1'], span=100)[a:b].plot(color='blue', label='smoothed')
legend()
<matplotlib.legend.Legend at 0x10ea42f90>
from sympy import *
v = symbols('v')
integrate(log(v), v)
v*log(v) - v
$1.15M Sloan Foundation Grant
Installing everything in Ubuntu is easy
sudo apt-get install ipython-notebook
In another OS it might give you some headache - better to install a Python distribution such as Enthought or Python(x,y)
Take a stroll to the cheese shop for the necessary packages
sudo pip install ipython[notebook]
If you're not using IPython, you're doing something wrong.
-- Wes McKinney, creator of Pandas and author of "Python for Data Analysis"