{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "This page has been moved to [https://econ.pages.code.wm.edu/414/syllabus/docs/index.html](https://econ.pages.code.wm.edu/407/notes/docs/index.html) and is no longer being maintained here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This short guide will help you get started with the anaconda python distribution on your PC or MAC. If you happen to run linux, please contact Professor Hicks directly.\n", "\n", "**Important Note**: \n", "\n", ">Please use a pristine Anaconda Python install for this class. If you have an existing Anaconda install that you would like to keep, please see me about your options. If you have an existing Anaconda install, and don't care to keep it, just delete the folder prior to initiating the installation steps below. Just take care to save any of your work in the Anaconda folder before deleting it.\n", "\n", "# Installing Python\n", "\n", "Both the PC and MAC installers can be downloaded at [https://www.anaconda.com/download/](https://www.anaconda.com/download/). Choose the 64bit Python 3.x version for your platform (3.7 at the time of this writing).\n", "\n", "This short guide will help you get started with the anaconda python distribution on your PC or MAC. If you happen to run linux, please contact Professor Hicks directly." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Once you have downloaded the installer, do the following:\n", "\n", "1. Navigate to your your browser's download folder \n", "2. Open the python executable downloaded in step (1) (e.g. Anaconda-3.x.x-Windows-x_86_64.exe [PC] or Anaconda-3.x-mac-x_86_64.dmg [MAC])\n", "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. \n", "\n", "\n", "# Using Python\n", "\n", "Now that python is installed 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.\n", "\n", "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 `jupyter 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.\n", "\n", "In case you can't find the Anaconda icon, you can also launch it from the terminal or command prompt window, type `jupyter notebook`. \n", "\n", "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):\n", "![](../site_pics/ipython_main.png)\n", "\n", "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` as shown below [Note, the screenshot below is from an old python version and shows `Python 2`):\n", "\n", "![](../site_pics/ipython_main2.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Testing the installation\n", "\n", "Having created a new notebook, you should see a window that looks like this:\n", "![](../site_pics/notebook1.png)\n", "\n", "You can re-name your new untitled notebook by clicking on ``Untitled`` and changing the name:\n", "![](../site_pics/notebook2.png)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Ipython Notebooks have execution blocks where you can enter and execute python code. These blocks look like this:\n", "![](../site_pics/execute.png)\n", "\n", "Copy and paste the following code into the first (and only at this point) execution block:\n", "```\n", "%matplotlib inline\n", "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import statsmodels.formula.api as sm\n", "import sympy as sympy\n", "```\n", "\n", "You should see output like this after pressing the `shift enter` keys at the same time to execute the code:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "%matplotlib inline\n", "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import statsmodels.formula.api as sm\n", "import sympy as sympy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we will make sure things are working. Paste this code into the next execution cell and press ``shift enter``:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | time | \n", "price | \n", "
---|---|---|
count | \n", "100.000000 | \n", "100.000000 | \n", "
mean | \n", "50.500000 | \n", "9.589623 | \n", "
std | \n", "29.011492 | \n", "3.293449 | \n", "
min | \n", "1.000000 | \n", "3.864494 | \n", "
25% | \n", "25.750000 | \n", "7.160937 | \n", "
50% | \n", "50.500000 | \n", "9.162188 | \n", "
75% | \n", "75.250000 | \n", "11.723528 | \n", "
max | \n", "100.000000 | \n", "19.286071 | \n", "