# Python: Getting Started

NB: anything prefixed with a $ and looking like code is a command to run at the command line.

Wherever possible we'll reuse existing material and will concentrate on material specific to economists. Works that we will refer to include:

[1]: Main Python Tutorial (sections 1-7)

[2]: Dive Into Python

Finally, remember that if you encounter any difficulties:

**search on the web**.- Add your comments here.

## Installation

This is the absolute basics. See [2] for more details/help on installation.

- Install python.
- On any linux distro this will be installed by default
- On windows may need to download (and alter your default path as we will be using python from the command line a lot)

- Install some additional modules. The easiest way to do this is to use setuptools and easy_install (again on linux this would be much easier ...)
install setuptools by downloading ez_setup.py and running it

- install scipy:
`$ easy_install scipy`

- install matplotlib -- warning this needs extra libraries than the basic python in order to render graphics (if you want to do more than simply write to disk)
debian/ubuntu

`$ apt-get install matplotlib`windows:

`$ easy_install matplotlib`(then may need to do more to get graphics working)

## Doing Something

Use [1], [2] or any other tutorial you can find to:

- Heavily recommend reading/working through sections 2-7 of [1] especially sections 3-5 (absolutely essential!)
- Write a function/method that given a list of integers computes (and returns):
- their sum
- their squared sum
- the sum of an arbitrary function f of each of their values (i.e. $$f(x_{1}) + f(x_{2}) + ...$$). f should obviously now be an additional argument to this function

- Download files and extract information
Suggested file is: http://mdgs.un.org/unsd/mdg/Handlers/ExportHandler.ashx?Type=Csv&Series=699

- This is from the Millenium Development Goals series and is: "Purchasing power parities (PPP) conversion factor, local currency unit to international dollar"

- Download using urllib.urlopen and urllib.urlretrieve
- Having downloaded the file extract its contents using python's zipfile library
- This is a csv file so now use python's csv library to read into a scipy/numpy array or a simply python list of lists

- Plot graphs using matplotlib
- e.g. $$y=x, y=x^{2}, y=cos(x)$$ etc)
- The PPP material downloaded in the previous step. (use bar chart from pylab/matplotlib)

Using numpy/scipy: main tutorial is here http://www.scipy.org/SciPy_Tutorial

- Create a simple random matrix and compute its eigenvalues
- Plot the spectrogram of its eigenvalues.