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]:
In [3]:
s.head(3)
s.tail()
Out[3]:
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]:
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]:
In [8]:
s2 = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])
s2['a']
Out[8]:
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
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)
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]:
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]:
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);
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