2+2 log(1) z = [1, 2, 3] z type(z) z * 2 import numpy numpy.log(1) import numpy as np np.log(1) x = np.array(z) x * 2 type(x) np.tile(x,2) x[1] x[0:2] y = x x[2] = 10 x y x is y x = np.arange(0,3) x y = np.copy(x) x[2] = 10 x y a = 1 b = a a = 2 b def addone(a): a += 1 return(a) x = np.array([1, 2]) addone(x) x import scipy as sp z = sp.randn(10) z from scipy import stats stats.norm.cdf(1.645) np.mean(z) sp.mean(z) z.mean() import pandas as pd gala = pd.read_table('http://people.bath.ac.uk/jjf23/data/gala.dat',index_col=0,delim_whitespace=True) gala.head() type(gala) gala.describe().round(1) gala.Species gala['Species'] gala.iloc[0] gala.iloc[-2:,0:3] gala[gala.Species == gala.Endemics] import seaborn.apionly as sns iris = sns.load_dataset('iris') iris.head() iris.groupby('species').agg({'sepal_length': np.mean, 'sepal_width' : np.mean}) import matplotlib.pyplot as plt get_ipython().run_line_magic('matplotlib', 'inline') x = np.linspace(0, 2 * np.pi) y = np.sin(x) plt.plot(x, y) plt.scatter(gala.Area, gala.Elevation) plt.xlabel("Area") plt.ylabel("Elevation") import statsmodels.api as sm x = gala.iloc[:,2:] y = gala.Species lmod = sm.OLS(y,sm.add_constant(x)).fit() lmod.summary() import statsmodels.formula.api as smf lmod = smf.ols('Species ~ Area + Elevation + Nearest + Scruz + Adjacent', data=gala).fit() lmod.summary() lmod2 = smf.ols('Species ~ Area + Elevation + Nearest + Scruz + Adjacent + I(Area + Adjacent)', data=gala).fit() lmod2.summary() lmod.params plt.scatter(lmod.fittedvalues, lmod.resid) plt.axhline(0) sm.qqplot(lmod.resid, line='r')