In [1]:
%matplotlib inline

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

N = 300
a = 0.9
b = 0.2

x = np.ndarray((N,))
x[0] = 0.0
for i in range(N-1):
    x[i+1] = a*x[i] + b*np.random.randn(1)

plt.plot(x)
plt.show()



In [2]:
s = pd.Series(x)
s[[0,1,3,8,10]]


Out[2]:
0     0.000000
1    -0.250405
3    -0.100635
8     0.298278
10    0.569177
dtype: float64

In [3]:
s.head(3)
s.tail()


Out[3]:
295   -0.095256
296   -0.210249
297    0.007762
298   -0.029699
299   -0.083629
dtype: float64

In [2]:
df2 = pd.DataFrame([1,2,5,3],index=['a','b','c','d'])

df3 = df2.reindex(index=['a','b','c','e','f'])
pd.DatetimeIndex


Out[2]:
pandas.tseries.index.DatetimeIndex

In [3]:
#df_enerji = pd.read_csv(u'/Users/cemgil/src/p1m1/predictive_maintenance/energy/enerji_input.csv',sep=';')
df = pd.read_csv(u'sp500f.csv',sep=',', index_col='Symbol',usecols=[0,1,2,3,7])

df.Price
df.Price.align


Out[3]:
<bound method Series.align of Symbol
MMM      177.12
ABT       41.89
ABBV      64.16
ACN      115.11
ATVI      41.29
AYI      264.62
ADBE      96.79
AAP      164.85
AES       12.32
AET      117.00
AMG      138.85
AFL       72.49
A         45.48
APD      144.35
AKAM      56.38
ALK       59.86
ALB       83.58
AA         9.82
ALXN     124.42
ALLE      69.74
AGN      240.59
ADS      200.96
LNT       40.55
ALL       69.66
GOOGL    717.78
GOOG     705.63
MO        69.83
AMZN     745.81
AEE       53.15
AAL       30.04
          ...  
V         76.42
VNO      100.46
VMC      123.61
WMT       73.84
WBA       81.80
WM        67.61
WAT      146.53
WFC       47.79
HCN       75.62
WDC       49.35
WU        19.57
WRK       38.55
WY        30.67
WHR      171.38
WFM       33.58
WMB       20.99
WLTW     125.06
WEC       65.03
WYN       72.35
WYNN      89.75
XEL       44.59
XRX        9.54
XLNX      46.97
XL        33.01
XYL       46.41
YHOO      37.74
YUM       85.76
ZBH      124.89
ZION      24.74
ZTS       48.50
Name: Price, dtype: float64>

In [8]:
s2 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
s2['a']


Out[8]:
1

In [9]:
s3 = pd.Series('Relations between mathematicians and engineers are based on trust and understanding. Namely, mathematicians do not trust engineers, and engineers do not understand mathematicians')

In [ ]:
x = 5
print(x)

This is my result for the function

$$f(x) = 5x $$

In [ ]:
x*5

Heading

Subtitle

$3x^2 + 5x - 7$


In [ ]:
a = 3
b = 5
c = -7 

print(a*x**2 + b*x + c)

In [ ]:
print('*+'*30)

In [ ]:
for i in range(0,10,2):
    print(i)

In [ ]:
for x in range(-5,6):
    print(x)
    print(a*x**2 + b*x + c)

In [ ]:
for b in range(1,11):
    for a in range(1,11):
        print (a*b),
    print

Print Fibionacci numbers

1 1 2 1 3 2 4 3 5 5 6 8 7 13 8 21

1 1 1 2 4 8 3 9 27 ... 10


In [ ]:
for x in range(11):
    print(x, x**2, x**3)

$x_1 = 1$

$x_t = 2x_{t-1} + 1$

$x_1 = 1$

$x_2 = 3$

$x_3 = 7$


In [ ]:
x = 1
for i in range(10):
    print(i+1, x)
    x = 2*x + 1

In [10]:
import pandas as pd

s = pd.Series(np.random.randn(100))

In [4]:
import pandas.io.data as web
#import pandas_datareader as web
import datetime

start = datetime.datetime(2013, 1, 1)
end = datetime.datetime(2013, 12, 30)
msft = web.DataReader("MSFT", 'yahoo', start, end)
aapl = web.DataReader("AAPL", 'yahoo', start, end)


/Users/cemgil/anaconda/envs/py35/lib/python3.5/site-packages/pandas/io/data.py:35: FutureWarning: 
The pandas.io.data module is moved to a separate package (pandas-datareader) and will be removed from pandas in a future version.
After installing the pandas-datareader package (https://github.com/pydata/pandas-datareader), you can change the import ``from pandas.io import data, wb`` to ``from pandas_datareader import data, wb``.
  FutureWarning)

In [5]:
msft.reindex(index=['2013-01-03', '2013-01-04', '2013-01-05', '2013-01-06','2013-01-09', '2013-01-10'])


Out[5]:
Open High Low Close Volume Adj Close
Date
2013-01-03 NaN NaN NaN NaN NaN NaN
2013-01-04 NaN NaN NaN NaN NaN NaN
2013-01-05 NaN NaN NaN NaN NaN NaN
2013-01-06 NaN NaN NaN NaN NaN NaN
2013-01-09 NaN NaN NaN NaN NaN NaN
2013-01-10 NaN NaN NaN NaN NaN NaN

In [6]:
z = msft['Open'].iloc[0:]

In [7]:
z = aapl
log_ret = np.log(z['Open']/z['Close'])
log_ret

plt.figure(figsize=(12,3))
plt.plot(log_ret.values)
plt.show()



In [8]:
idx = log_ret[0:30:5].index

In [9]:
u = msft.reindex(idx)

In [10]:
u


Out[10]:
Open High Low Close Volume Adj Close
Date
2013-01-02 27.250000 27.730000 27.150000 27.620001 52899300 24.891298
2013-01-09 26.719999 26.750000 26.559999 26.700001 49047900 24.062189
2013-01-16 27.150000 27.230000 27.010000 27.040001 41077400 24.368599
2013-01-24 27.700001 28.070000 27.469999 27.629999 101739300 24.900308
2013-01-31 27.790001 27.969999 27.400000 27.450001 50530000 24.738093
2013-02-07 27.350000 27.389999 27.100000 27.280001 38028300 24.584888

In [14]:
from pythreejs import *

f = """
function f(origu,origv) {
    // scale u and v to the ranges I want: [0, 2*pi]
    var u = 2*Math.PI*origu;
    var v = 2*Math.PI*origv;
    
    var x = Math.sin(u);
    var y = Math.cos(v);
    var z = Math.cos(u+v);
    
    return new THREE.Vector3(x,y,z)
}
"""

surf_g = ParametricGeometry(func=f);
surf = Mesh(geometry=surf_g, material=LambertMaterial(color='green', side='FrontSide'))
surf2 = Mesh(geometry=surf_g, material=LambertMaterial(color='yellow', side='BackSide'))
scene = Scene(children=[surf, surf2, AmbientLight(color='#777777')])
c = PerspectiveCamera(position=[2.5, 2.5, 2.5], up=[0, 0, 1],
                      children=[DirectionalLight(color='white',
                                                 position=[3, 5, 1],
                                                 intensity=0.6)])
Renderer(camera=c, scene=scene, controls=[OrbitControls(controlling=c)])

In [15]:
from __future__ import print_function
from ipywidgets import interact, interactive, fixed
import ipywidgets as widgets

In [16]:
import numpy as np
def f(x):
    return np.log(x)

interact(f, x=10);


2.3025850929940459

In [17]:
%matplotlib inline
import matplotlib.pylab as plt
from IPython.display import clear_output, display, HTML

fig, ax = plt.subplots()
ax.plot([3,1,2,4,0,5,3,2,0,2,4])
plt.close(fig)

vline = ax.axvline(1)
hline = ax.axhline(0.5)

def set_cursor(x, y):
    vline.set_xdata((x, x))
    hline.set_ydata((y, y))
    display(fig)

interact(set_cursor, x=(1, 9, 0.01), y=(0, 5, 0.01))



In [ ]:
%connect_info