# Python Installation Instructions

## Installing Python¶

Take care that you are downloading Python 3.x (which is the default) for your platform. The 64bit version (also the default) is what you want in 99% of all cases.

2. Open the python executable (e.g. Anaconda3-4.3.1-Windows-x86_64.exe [PC] or Anaconda3-4.3.1-MacOSX-x86_64.pkg [MAC])
3. Click through the install screens and choose to install "Just Me" and don't change the default install location. Leave any "Advanced Options" at their default values.

## Using Python¶

Now that python is installed and updated, we can use it. There are several ways to run python code, and I will show you a method allowing you to use your web browser as a "front-end" for python.

We will be using the Ipython Notebook (now called Jupyter). The easiest way to open it is to locate and use the Anaconda Launcher. Hopefully, the install process will put this in your Program Files (PC) or Applications (Mac). If you see a new icon labeled Anaconda Launcher, click it and choose ipython notebook. Sometimes, the install process doesn't create the Anaconda icon. In this case, it is possible to locate it in the Anaconda folder in your local home directory.

In case you can't find the Anaconda icon, you can also launch it from the terminal or command prompt window, type ipython notebook.

If you have made it this far, your web browser should pop up and you should see a window like this (note: the actual filenames and folders you will see will reflect the actual information you have on your computer):

This listing allows you to see existing and running Ipython Notebooks. You won't have any, so let's create one. You can navigate to a folder of your choosing and create a new notebook by clicking on New and then Python 3 [note the screenshot below is old and show Python 2] as shown below:

### Testing the installation¶

Having created a new notebook, you should see a window that looks like this:

You can re-name your new untitled notebook by clicking on Untitled and changing the name:

Ipython Notebooks have execution blocks where you can enter and execute python code. These blocks look like this:

Copy and paste the following code into the first (and only at this point) execution block:

%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib pyplot as plt
import statsmodels.formula.api as sm
import sympy as sympy

You should see output like this after pressing the shift enter keys at the same time to execute the code:

In [1]:
%matplotlib inline
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.formula.api as sm
import sympy as sympy


Next, we will make sure things are working. Paste this code into the next execution cell and press shift enter:

In [2]:
# create some toy data
time=np.arange(1,101)
price = np.random.normal(10,3,(np.size(time)))

df = pd.DataFrame(zip(time,price),columns=['time','price'])

# run summary statistics
df.describe()

Out[2]:
time price
count 100.000000 100.000000
mean 50.500000 9.866077
std 29.011492 2.946530
min 1.000000 2.643740
25% 25.750000 8.113189
50% 50.500000 9.724360
75% 75.250000 11.569507
max 100.000000 18.147543

We can also visualize our data easily using the pandas package:

In [3]:
# plot histogram of price
df.price.plot(kind='hist')

Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f0a1deddfd0>
In [4]:
# or a trace plot through time:
df.price.plot()

Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f09e1adb050>

Next we will test the statsmodels library:

In [5]:
import statsmodels.formula.api as smf
formula = "price ~ time"
results = smf.ols(formula,df).fit()
print(results.summary())

                            OLS Regression Results
==============================================================================
Dep. Variable:                  price   R-squared:                       0.002
Method:                 Least Squares   F-statistic:                    0.2010
Date:                Tue, 25 Aug 2015   Prob (F-statistic):              0.655
Time:                        07:35:12   Log-Likelihood:                -249.35
No. Observations:                 100   AIC:                             502.7
Df Residuals:                      98   BIC:                             507.9
Df Model:                           1
Covariance Type:            nonrobust
==============================================================================
coef    std err          t      P>|t|      [95.0% Conf. Int.]
------------------------------------------------------------------------------
Intercept      9.6340      0.596     16.160      0.000         8.451    10.817
time           0.0046      0.010      0.448      0.655        -0.016     0.025
==============================================================================
Omnibus:                        0.653   Durbin-Watson:                   2.125
Prob(Omnibus):                  0.721   Jarque-Bera (JB):                0.250
Skew:                           0.036   Prob(JB):                        0.883
Kurtosis:                       3.234   Cond. No.                         117.
==============================================================================

Warnings:
[1] Standard Errors assume that the covariance matrix of the errors is correctly specified.


## Markdown Text and Notebook Annotations¶

Changing the execution cell type to markdown here:

allows you to enter markdown compliant passages and get nicely formatted text when you execute the cell by pressing shift enter. For example, executing the following markdown code in a markdown execution cell:

This is some markdown code.  I can type sentences and paragraphs here.  Or, if I want a numbered list, here it is:

1. Dogs
2. Cats
3. Elephants

I can include links in my markdown passages:
![](https://whyevolutionistrue.files.wordpress.com/2012/08/cute-kitten-saying-hello.jpg)

And I can include latex equations inline: $\frac{\alpha}{\beta}$.  Or I can put them on their own line
$$W_j = \sum_{i\ne j} W_{ij} \epsilon_i$$

results in this output:

This is some markdown code. I can type sentences and paragraphs here. Or, if I want a numbered list, here it is:

1. Dogs
2. Cats
3. Elephants

I can include links in my markdown passages:

And I can include latex equations inline: $\frac{\alpha}{\beta}$. Or I can put them on their own line $$W_j = \sum_{i\ne j} W_{ij} \epsilon_i$$