In [2]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
In [3]:
url = "http://donnees.ville.montreal.qc.ca/storage/f/2014-01-20T20%3A48%3A50.296Z/2013.csv"
In [4]:
df = pd.read_csv(url, index_col='Date',
parse_dates=True, dayfirst=True)
In [5]:
df.head(2)
Out[5]:
In [6]:
df.describe()
Out[6]:
In [7]:
df[['Berri1', 'PierDup']].plot()
Out[7]:
In [9]:
from IPython.html.widgets import interact
@interact
def plot(n=(1, 30)):
pd.rolling_mean(df['Berri1'], n).dropna().plot()
plt.ylim(0, 8000)
plt.show()
In [10]:
import random
%precision 3
Out[10]:
In [13]:
n = 1000000
x = [random.random() for _ in range(n)]
y = [random.random() for _ in range(n)]
x[:3], y[:3]
Out[13]:
In [15]:
%%timeit
z = [x[i] + y[i] for i in range(n)]
In [16]:
xa = np.array(x)
ya = np.array(y)
xa[:3]
Out[16]:
In [19]:
%timeit za = xa + ya
In [20]:
da = np.abs(xa[:1000,None] - ya[:1000])
da
Out[20]:
In [22]:
%timeit [abs(x[i] - y[j]) for i in range(1000) for j in range(1000)]
%timeit np.abs(xa[:1000,None] - ya[:1000])
In [30]:
test1 = [1,2,3,4]
atest1 = np.array(test1)
test1
atest1[:,None]
Out[30]:
In [31]:
xa[:13,None] - ya[:3]
Out[31]:
In [33]:
from IPython.core.magic import (register_line_magic, register_cell_magic)
import pandas as pd
from StringIO import StringIO # Python 2
#from io import StringIO # Python 3
@register_cell_magic
def csv(line, cell):
# We create a string buffer containing the
# contents of the cell.
sio = StringIO(cell)
# We use pandas' read_csv function to parse
# the CSV string.
return pd.read_csv(sio)
In [34]:
%%csv
col1,col2,col3
0,1,2
3,4,5
6,7,8
Out[34]:
In [36]:
mydef = _
mydef.describe()
Out[36]:
In [ ]: