├── .gitignore
├── Docker-Instructions.rst
├── LICENSE
├── Lecture 1
├── Exercise 1
│ ├── README.md
│ ├── test-notebook.ipynb
│ └── test-script.py
├── Lecture 1 - Introduction to Python.ipynb
└── imgs
│ ├── ipython.png
│ ├── jupyter.png
│ ├── python.png
│ └── spyder.png
├── Lecture 2
├── Exercise 2 - Solutions.ipynb
├── Exercise 2.ipynb
├── Lecture 2 - Python Basics (Completed).ipynb
└── Lecture 2 - Python Basics (Template).ipynb
├── Lecture 3
├── Exercise 3 - Solutions.ipynb
├── Exercise 3.ipynb
├── Lecture 3 - Numpy + Pandas I (Complete).ipynb
├── Lecture 3 - Numpy + Pandas I (Template).ipynb
└── data
│ ├── asia_gdp_per_capita.csv
│ ├── baseball.csv
│ ├── gapminder_all.csv
│ ├── gapminder_gdp_africa.csv
│ ├── gapminder_gdp_americas.csv
│ ├── gapminder_gdp_asia.csv
│ ├── gapminder_gdp_europe.csv
│ ├── gapminder_gdp_oceania.csv
│ ├── microbiome.csv
│ ├── microbiome
│ ├── MID1.xls
│ ├── MID2.xls
│ ├── MID3.xls
│ ├── MID4.xls
│ ├── MID5.xls
│ ├── MID6.xls
│ ├── MID7.xls
│ ├── MID8.xls
│ ├── MID9.xls
│ └── metadata.xls
│ └── microbiome_missing.csv
├── Lecture 4
├── Exercise 4 - Solutions.ipynb
├── Exercise 4.ipynb
├── Lecture 4 - Pandas II (Complete).ipynb
├── Lecture 4 - Pandas II (Template).ipynb
└── data
│ ├── AIS
│ ├── transit_segments.csv
│ └── vessel_information.csv
│ ├── beer_subset.csv.gz
│ ├── cdystonia.csv
│ ├── cpi.csv
│ ├── gdp.csv
│ └── rec.csv
├── Lecture 5
├── Lecture 5 - Pandas III (Complete).ipynb
├── Lecture 5 - Pandas III (Template).ipynb
└── data
│ └── beer_subset.csv.gz
├── Lecture 6
├── Lecture 6 - Plotting (Complete).ipynb
├── Lecture 6 - Plotting (Template).ipynb
└── data
│ ├── beer_subset.csv.gz
│ └── titanic.xls
├── Lecture 7
├── Lecture 7 - Intro to Modeling in Python (Complete).ipynb
├── Lecture 7 - Intro to Modeling in Python (Template).ipynb
└── data
│ └── cd4.csv
├── README.rst
├── docs
├── Makefile
├── _build
│ └── .gitignore
├── _static
│ └── .gitignore
├── _templates
│ └── .gitignore
├── conf.py
├── index.rst
├── make.bat
└── numpy.rst
└── np_sec
├── answers.py
├── gbd_example.jinja
├── prepare_data.py
└── working.py
/.gitignore:
--------------------------------------------------------------------------------
1 | # Byte-compiled / optimized / DLL files
2 | __pycache__/
3 | *.py[cod]
4 | *$py.class
5 |
6 | # C extensions
7 | *.so
8 |
9 | # Distribution / packaging
10 | .Python
11 | build/
12 | develop-eggs/
13 | dist/
14 | downloads/
15 | eggs/
16 | .eggs/
17 | lib/
18 | lib64/
19 | parts/
20 | sdist/
21 | var/
22 | wheels/
23 | *.egg-info/
24 | .installed.cfg
25 | *.egg
26 | MANIFEST
27 |
28 | # PyInstaller
29 | # Usually these files are written by a python script from a template
30 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
31 | *.manifest
32 | *.spec
33 |
34 | # Installer logs
35 | pip-log.txt
36 | pip-delete-this-directory.txt
37 |
38 | # Unit test / coverage reports
39 | htmlcov/
40 | .tox/
41 | .coverage
42 | .coverage.*
43 | .cache
44 | nosetests.xml
45 | coverage.xml
46 | *.cover
47 | .hypothesis/
48 |
49 | # Translations
50 | *.mo
51 | *.pot
52 |
53 | # Django stuff:
54 | *.log
55 | .static_storage/
56 | .media/
57 | local_settings.py
58 |
59 | # Flask stuff:
60 | instance/
61 | .webassets-cache
62 |
63 | # Scrapy stuff:
64 | .scrapy
65 |
66 | # Sphinx documentation
67 | docs/_build/
68 |
69 | # PyBuilder
70 | target/
71 |
72 | # Jupyter Notebook
73 | .ipynb_checkpoints
74 |
75 | # pyenv
76 | .python-version
77 |
78 | # celery beat schedule file
79 | celerybeat-schedule
80 |
81 | # SageMath parsed files
82 | *.sage.py
83 |
84 | # Environments
85 | .env
86 | .venv
87 | env/
88 | venv/
89 | ENV/
90 | env.bak/
91 | venv.bak/
92 |
93 | # Spyder project settings
94 | .spyderproject
95 | .spyproject
96 |
97 | # Rope project settings
98 | .ropeproject
99 |
100 | # mkdocs documentation
101 | /site
102 |
103 | # mypy
104 | .mypy_cache/
105 |
--------------------------------------------------------------------------------
/Docker-Instructions.rst:
--------------------------------------------------------------------------------
1 | Install Docker
2 | ==============
3 |
4 | Docker enables you to create "containers" which provide consistent
5 | environments in which to run your code. This way, you can run the
6 | software you write on different machines (e.g. your laptop vs the
7 | computing cluster) without having to spend too much time worrying about
8 | adapting it.
9 |
10 | We're going to just be using some very basic features of Docker, so if
11 | you'd like to learn more refer to `this
12 | page `__.
13 |
14 | Windows 10
15 | ----------
16 |
17 | Detailed installation instructions are available
18 | `here `_. For our
19 | purposes, you can simply:
20 |
21 | 1. `Download `_
22 | the installer.
23 |
24 | 2. Double click on the installer and follow the prompts (keeping all
25 | options as defaults is fine).
26 |
27 | 3. Open a shell (e.g. ``cmd.exe``) and trying running the test example:
28 |
29 | ::
30 |
31 | docker run hello-world
32 |
33 | Windows 7 and Windows 8
34 | -----------------------
35 |
36 | Detailed installation instructions are available
37 | `here `_. Be warned,
38 | however, that some people at IHME with older Lenovo laptops have had trouble
39 | getting them to work.
40 |
41 | Mac OSX
42 | -------
43 |
44 | Detailed installation instructions are available
45 | `here `_. For our purposes,
46 | you can simply:
47 |
48 | 1. `Download `_ the
49 | installer.
50 |
51 | 2. Double click on the installer and drag ``Docker.app`` into your
52 | Applications folder.
53 |
54 | 3. Double click on ``Docker.app`` to start Docker.
55 |
56 | 4. Open a shell (e.g. ``terminal.app``) and trying running the test
57 | example:
58 |
59 | ::
60 |
61 | docker run hello-world
62 |
63 | Unix/Linux
64 | ----------
65 |
66 | ¯\\\_(ツ)_/¯
67 |
68 | Install Anaconda
69 | ================
70 |
71 | Anaconda is a software package for Python (and R and sometimes C...)
72 | that handles the installation of common Python packages for you, making
73 | it easier to create and manage portable environments. We'll be using it
74 | inside of Docker to ensure that everyone is running under the same
75 | environment. See `this page `_
77 | for more on how Docker and Anaconda fit together.
78 |
79 | 1. Get the latest Anaconda for Python 3 image:
80 |
81 | ::
82 |
83 | docker pull continuumio/anaconda3
84 |
85 | 2. Test that your installation worked:
86 |
87 | ::
88 |
89 | docker run continuumio/anaconda3 /opt/conda/bin/conda info
90 |
91 |
92 | Running Jupyter Notebooks via Docker
93 | ------------------------------------
94 |
95 | 1. You can fire up a notebook using the following command:
96 |
97 | ::
98 |
99 | docker run -it -p 8888:8888 -v ~/repos/ihme-python-course/:/home/ihme-python-course/ continuumio/anaconda3 /opt/conda/bin/jupyter notebook --ip='*' --no-browser --notebook-dir=/home/ihme-python-course/
100 |
101 | What do all of these arguments mean?
102 |
103 | +------------------------------+-------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
104 | | Argument | Value | Description |
105 | +==============================+=============================================================+====================================================================================================================+
106 | | ``-it`` | | Run the Docker container interactively |
107 | +------------------------------+-------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
108 | | ``-p`` | ``8888:8888`` | Map the 8888 port of the Docker container to the local port so that you can connect to it via your web browser |
109 | +------------------------------+-------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
110 | | ``-v`` | ``~/repos/ihme-python-course/:/home/ihme-python-course/`` | Maps ``:`` so that the repo you've downloaded is visible to the container |
111 | +------------------------------+-------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
112 | | ``continuumio/anaconda3`` | | The name of the Docker container to be run |
113 | +------------------------------+-------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
114 | | ``/opt/conda/bin/jupyter`` | | The program to execute inside of the container (Jupyter) |
115 | +------------------------------+-------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
116 | | ``notebook`` | | This tells Jupyter to start a Notebook server |
117 | +------------------------------+-------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
118 | | ``--ip`` | ``'*'`` | Configures Jupyter to respond to any user that can connect to the container |
119 | +------------------------------+-------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
120 | | ``--no-browser`` | | Prevents Jupyter from trying to automatically launch a web browser, since the Docker container does not have one |
121 | +------------------------------+-------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
122 | | ``--notebook-dir`` | ``/home/ihme-python-course/`` | Sets the root directory for the Jupyter server to the same one mapped under ``-v`` |
123 | +------------------------------+-------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+
124 |
125 | If you've followed all of the directions above exactly, you shouldn't
126 | need to edit any of these right now. If you've saved into a
127 | non-standard location, you may need to change the first part of your
128 | ``-v`` argument.
129 |
130 | There are many more options you can specify. See the corresponding `Docker
131 | `_ and `Jupyter
132 | `_ documentation.
134 |
135 | 2. Navigate to `localhost:8888 `_ in your web browser.
136 | You should see a listing of the files and directories inside this repo.
137 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | This work is licensed under the Creative Commons Attribution 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/us/ or send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
2 |
3 |
--------------------------------------------------------------------------------
/Lecture 1/Exercise 1/README.md:
--------------------------------------------------------------------------------
1 | # Exercise 1
2 |
3 | ## Installing Anaconda
4 |
5 | See [the README](../README.rst) for instructions on how to install Anaconda
6 | on your system.
7 |
8 |
9 | ## Clone this repo
10 | See [the README](../README.rst) again for instructions on cloning this repo
11 | (into its recommended location of `~/repos/`).
12 |
13 |
14 | ## Opening the `python` interpreter
15 |
16 | - Open up your terminal and type `python` at the command line
17 | - Try typing some things in to see how they work... some suggestions:
18 | * `1 + 1`
19 | * `1.0 + 1`
20 | * `"hello world"`
21 | * `print("hello world")`
22 | - Type `exit()` to exit
23 |
24 |
25 | ## Running `ipython`
26 |
27 | - Open up the interactive IPython interpreter
28 | * `ipython`
29 | - Try some of the same inputs as above
30 | - Type `print?` and hit `return`
31 | - Type `print(` and hit `tab`
32 | - Type `exit()` to exit
33 |
34 |
35 | ## Exploring `jupyter notebook`
36 |
37 | - Open up a terminal and navigate to the root directory of this repo (e.g.
38 | `~/repos/ihme-python-course`)
39 | - Type `jupyter notebook` to startup a notebook server
40 | - Your web browser will most likely automatically open
41 | * If not, you can navigate to
42 | [http://localhost:8888/](http://localhost:8888/)
43 | * _Note_: if you're already running something on port `8888` it might start
44 | the server on a different port. Look for a message in your terminal
45 | like
46 | The Jupyter Notebook is running at: http://localhost:8889/
47 | to find it.
48 | - Use the file tree to navigate to the `Lecture 1/Exercise 1` directory and
49 | and then click on `test-notebook.ipynb` to open it
50 | - Follow the instructions in the notebook
51 |
52 |
53 | ## Run a script from the command line
54 |
55 | - Examine [Exercise 1/test-script.py](Exercise 1/test-script.py) with your
56 | favorite editor or Spyder
57 | - Run it from the command line
58 | * _Hint_: remember `python my-script.py`
59 | - Change the message from "hello world" to something else and execute it
60 |
61 |
62 | ## _Optional_: Install `RISE`
63 |
64 | - [`RISE`](https://github.com/damianavila/RISE) will add a new button to your
65 | Jupyter toolbar that'll allow you to view these notebooks in slideshow mode
66 | - Click the new bargraph-esque icon in the toolbar to start a slideshow
67 | - Use `spacebar` and `shift+spacebar` to navigate through the slides
68 | - To edit how the slideshow is structured, take a look at
69 | `View > Cell Toolbar > Slideshow`
70 |
--------------------------------------------------------------------------------
/Lecture 1/Exercise 1/test-notebook.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Test Jupyter Notebook"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "- Click `Help > User Interface Tour`\n",
15 | "- Use the arrow keys to go through the Tour"
16 | ]
17 | },
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {},
21 | "source": [
22 | "- In `Command Mode` highlight the cell below\n",
23 | " * Hit `Escape` if you're stuck in `Edit Mode`\n",
24 | "- Hit `Ctl+Enter` to execute the cell"
25 | ]
26 | },
27 | {
28 | "cell_type": "code",
29 | "execution_count": null,
30 | "metadata": {
31 | "collapsed": false
32 | },
33 | "outputs": [],
34 | "source": [
35 | "print('hello world')"
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "metadata": {},
41 | "source": [
42 | "- Use the down arrow to select the cell below\n",
43 | "- Hit `Enter` to switch to `Edit Mode`\n",
44 | "- Change the message to something else\n",
45 | "- Hit `Escape` to return to `Command Mode`\n",
46 | "- Use `Ctl+Enter` to execute the cell"
47 | ]
48 | },
49 | {
50 | "cell_type": "code",
51 | "execution_count": null,
52 | "metadata": {
53 | "collapsed": false
54 | },
55 | "outputs": [],
56 | "source": [
57 | "print('change me')"
58 | ]
59 | },
60 | {
61 | "cell_type": "markdown",
62 | "metadata": {},
63 | "source": [
64 | "- Hit `b` to add a new cell\n",
65 | "- Try entering some code and executing it"
66 | ]
67 | }
68 | ],
69 | "metadata": {
70 | "anaconda-cloud": {},
71 | "kernelspec": {
72 | "display_name": "Python [conda root]",
73 | "language": "python",
74 | "name": "conda-root-py"
75 | },
76 | "language_info": {
77 | "codemirror_mode": {
78 | "name": "ipython",
79 | "version": 3
80 | },
81 | "file_extension": ".py",
82 | "mimetype": "text/x-python",
83 | "name": "python",
84 | "nbconvert_exporter": "python",
85 | "pygments_lexer": "ipython3",
86 | "version": "3.5.2"
87 | }
88 | },
89 | "nbformat": 4,
90 | "nbformat_minor": 1
91 | }
92 |
--------------------------------------------------------------------------------
/Lecture 1/Exercise 1/test-script.py:
--------------------------------------------------------------------------------
1 | if __name__ == '__main__':
2 | print('hello world')
3 |
--------------------------------------------------------------------------------
/Lecture 1/Lecture 1 - Introduction to Python.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {
6 | "nbpresent": {
7 | "id": "1ac9ecee-f28a-462f-a772-e7cea9a82b07"
8 | },
9 | "slideshow": {
10 | "slide_type": "slide"
11 | }
12 | },
13 | "source": [
14 | "# Introduction to Python\n",
15 | "## Getting Started"
16 | ]
17 | },
18 | {
19 | "cell_type": "markdown",
20 | "metadata": {
21 | "nbpresent": {
22 | "id": "ba2291e8-4da1-4384-aed9-89d1352ed506"
23 | },
24 | "slideshow": {
25 | "slide_type": "slide"
26 | }
27 | },
28 | "source": [
29 | "## Schedule\n",
30 | "\n",
31 | "| Date | Session | Title | Description |\n",
32 | "|--------------|--------------|----------------------|----------------------------------------------|\n",
33 | "| Day 1 | Lecture 1 | Intro and Setup | *Why Python, Setup, etc* |\n",
34 | "| Day 1 | Lecture 2 | Basic Python | *Syntax, data structures, control flow, etc* |\n",
35 | "| Day 2 | Lecture 3 | Numpy + Pandas I | *Numpy basics, series/dataframe basics*|\n",
36 | "| Day 2 | Lecture 4 | Pandas II | *Joining, advanced indexing, reshaping, etc* |\n",
37 | "| Day 3 | Lecture 5 | Pandas III | *Grouping, apply, transform, etc* |\n",
38 | "| Day 3 | Lecture 6 | Plotting | *Intro to plotting in Python* |\n",
39 | "| Day 3 | Lecture 7 | Intro to Modeling | *Intro to stats/ML models in Python* |"
40 | ]
41 | },
42 | {
43 | "cell_type": "markdown",
44 | "metadata": {
45 | "nbpresent": {
46 | "id": "0f862571-7c07-4522-8b38-dee55d550f96"
47 | },
48 | "slideshow": {
49 | "slide_type": "slide"
50 | }
51 | },
52 | "source": [
53 | "## Course materials\n",
54 | "\n",
55 | "### [github.com/ihmeuw/ihme-python-course](https://github.com/ihmeuw/ihme-python-course)\n",
56 | "\n",
57 | "First, you're going to want to get a copy of this repository onto your\n",
58 | "machine. Simply fire up ``git`` and clone it:\n",
59 | "\n",
60 | "1. Open up a shell (e.g. ``git.exe``, ``cmd.exe``, or ``terminal.app``)\n",
61 | "\n",
62 | "2. Navigate to where you'd like to save this. \n",
63 | " - We recommend ``~/repos/`` (e.g. ``C:/Users//repos/`` on Windows, ``/Users//repos/`` on Mac, or ``/home//repos/`` on Unix).\n",
64 | "\n",
65 | "3. Clone this repo:\n",
66 | " git clone https://github.com/ihmeuw/ihme-python-course.git\n",
67 | " \n",
68 | "If you need help with setting up `git`, see [this page](https://help.github.com/articles/set-up-git/#setting-up-git) or simply download the repo as a [zip file](https://github.com/IHME/ihme-python-course/archive/master.zip) for now..."
69 | ]
70 | },
71 | {
72 | "cell_type": "markdown",
73 | "metadata": {
74 | "nbpresent": {
75 | "id": "d8735df1-cb35-45cb-97ce-0edb86f5c0f6"
76 | },
77 | "slideshow": {
78 | "slide_type": "slide"
79 | }
80 | },
81 | "source": [
82 | "\n",
83 | "\n",
84 | "via [xkcd](https://xkcd.com/353/) (see also [xkcd in python](https://pypi.python.org/pypi/xkcd/) and [xkcd for matplotlib](http://matplotlib.org/xkcd/examples/showcase/xkcd.html))"
85 | ]
86 | },
87 | {
88 | "cell_type": "markdown",
89 | "metadata": {
90 | "nbpresent": {
91 | "id": "cbb05c14-518f-433d-9e18-f6aca30a9ad5"
92 | },
93 | "slideshow": {
94 | "slide_type": "slide"
95 | }
96 | },
97 | "source": [
98 | "# What is Python? 🐍\n",
99 | "\n",
100 | "[Python](http://www.python.org/) is a widely used high-level, general-purpose, interpreted, dynamic programming language.\n",
101 | "\n",
102 | "## Broadly:\n",
103 | "\n",
104 | "Officially, Python is an interpreted scripting language (meaning that it is not compiled until it is run) for the C programming language; in fact, Python itself is coded in C (though there are other non-C implementations). It offers the power and flexibility of lower level (*i.e.* compiled) languages, without the steep learning curve and associated programming overhead. The language is very clean and readable, and it is available for almost every modern computing platform."
105 | ]
106 | },
107 | {
108 | "cell_type": "markdown",
109 | "metadata": {
110 | "nbpresent": {
111 | "id": "36363234-6fbb-42bd-b55d-6012593a7403"
112 | },
113 | "slideshow": {
114 | "slide_type": "slide"
115 | }
116 | },
117 | "source": [
118 | "## Advantages:\n",
119 | "\n",
120 | "* Ease of programming, minimizing the time required to develop, debug and maintain code\n",
121 | "* Well-designed language that encourages good programming practices:\n",
122 | " * Modular and object-oriented programming, good system for packaging and re-use of code\n",
123 | " * Documentation tightly integrated with the code\n",
124 | "* A large standard library with many extensions\n",
125 | "\n",
126 | "## Disadvantages:\n",
127 | "\n",
128 | "* Since Python is an interpreted and dynamically typed programming language, the execution of python code can be slow compared to compiled statically typed programming languages, such as C and Fortran\n",
129 | "* Somewhat decentralized, with different environments, packages and documentation spread out at different places"
130 | ]
131 | },
132 | {
133 | "cell_type": "markdown",
134 | "metadata": {
135 | "nbpresent": {
136 | "id": "8560f6c0-055f-4b75-9607-f1b330fa95ba"
137 | },
138 | "slideshow": {
139 | "slide_type": "slide"
140 | }
141 | },
142 | "source": [
143 | "# Scientific Computing in Python\n",
144 | "\n",
145 | "\n",
146 | "## Why do we use Python at IHME?\n",
147 | "\n",
148 | "- Powerful and easy to use\n",
149 | "- Interactive\n",
150 | "- Extensible\n",
151 | "- Large third-party library ecosystem\n",
152 | "- Free and open"
153 | ]
154 | },
155 | {
156 | "cell_type": "markdown",
157 | "metadata": {
158 | "nbpresent": {
159 | "id": "9b8de004-3973-4f9f-b34e-867d0a260445"
160 | },
161 | "slideshow": {
162 | "slide_type": "slide"
163 | }
164 | },
165 | "source": [
166 | "## Powerful and easy to use\n",
167 | "\n",
168 | "- Python is simultaneously powerful, flexible and easy to learn and use (in general, these qualities are traded off for a given programming language)\n",
169 | "- Anything that can be coded in C, FORTRAN, or Java can be done in Python, almost always in fewer (and more readable) lines of code, and with fewer debugging headaches\n",
170 | "- Its standard library is extremely rich, including modules for string manipulation, regular expressions, file compression, mathematics, profiling and debugging (*etc*)\n",
171 | "- Python is object-oriented, which is an important programming paradigm particularly well-suited to scientific programming, which allows data structures to be abstracted in a natural way"
172 | ]
173 | },
174 | {
175 | "cell_type": "markdown",
176 | "metadata": {
177 | "nbpresent": {
178 | "id": "0d1ba0ad-c734-4c74-b356-d95bad89cdb9"
179 | },
180 | "slideshow": {
181 | "slide_type": "slide"
182 | }
183 | },
184 | "source": [
185 | "## Interactive \n",
186 | "\n",
187 | "- Python may be run interactively on the command line, in much the same way as R\n",
188 | "- Notebooks offer convenient prototyping, mixing code in with outputs such as graphs and direct viewing of data structures\n",
189 | "- Rather than compiling and running a particular program, commands may entered serially which is often useful for mathematical programming and debugging"
190 | ]
191 | },
192 | {
193 | "cell_type": "markdown",
194 | "metadata": {
195 | "nbpresent": {
196 | "id": "63ba0d58-d09f-417b-8305-955ee07045f6"
197 | },
198 | "slideshow": {
199 | "slide_type": "slide"
200 | }
201 | },
202 | "source": [
203 | "## Extensible\n",
204 | "\n",
205 | "- Often referred to as a “glue” language, meaning that it is a useful in a mixed-language environment \n",
206 | " - (such as at IHME, where we often have to combine R, Stata, C++, etc)\n",
207 | "- Python was designed to interact with other programming languages, both through interfaces like [rpy2](http://rpy2.bitbucket.org/) and by compiling directly into Python extensions using e.g. [Cython](http://cython.org/)\n",
208 | "- New interfaces coming out all the time, such as for GPU computing"
209 | ]
210 | },
211 | {
212 | "cell_type": "markdown",
213 | "metadata": {
214 | "nbpresent": {
215 | "id": "29b82dc1-b5b9-48c5-9c60-bdc26452e190"
216 | },
217 | "slideshow": {
218 | "slide_type": "slide"
219 | }
220 | },
221 | "source": [
222 | "## Large third-party library ecosystem\n",
223 | "\n",
224 | "There are modules available for just about anything you could want to do in Python, with nearly 100,000 available on [PyPI](https://pypi.python.org/pypi) alone. Some notable packages:\n",
225 | "\n",
226 | "- [**NumPy**](http://www.numpy.org/): Numerical Python (NumPy) is a set of extensions that provides the ability to specify and manipulate array data structures. It provides array manipulation and computational capabilities similar to those found in Matlab or Octave. \n",
227 | "- [**SciPy**](http://www.scipy.org/): An open source library of scientific tools for Python, SciPy supplements the NumPy module. SciPy gathering a variety of high level science and engineering modules together as a single package. SciPy includes modules for graphics and plotting, optimization, integration, special functions, signal and image processing, genetic algorithms, ODE solvers, and others.\n",
228 | "- [**Matplotlib**](http://matplotlib.org/): Matplotlib is a python 2D plotting library which produces publication-quality figures in a variety of hardcopy formats and interactive environments across platforms. Its syntax is very similar to Matlab. \n",
229 | "- [**Pandas**](http://pandas.pydata.org/): A module that provides high-performance, easy-to-use data structures and data analysis tools. In particular, the `DataFrame` class is useful for spreadsheet-like representation and mannipulation of data. Also includes high-level plotting functionality.\n",
230 | "- [**IPython**](https://ipython.org/): An enhanced Python shell, designed to increase the efficiency and usability of coding, testing and debugging Python. It includes both a Qt-based console and an interactive HTML notebook interface, both of which feature multiline editing, interactive plotting and syntax highlighting."
231 | ]
232 | },
233 | {
234 | "cell_type": "markdown",
235 | "metadata": {
236 | "nbpresent": {
237 | "id": "57d3a95e-3eb6-4d24-b64b-5ee69c453fce"
238 | },
239 | "slideshow": {
240 | "slide_type": "slide"
241 | }
242 | },
243 | "source": [
244 | "## Free and open\n",
245 | "\n",
246 | "- Python is released on all platforms under an open license (Python Software Foundation License), meaning that the language and its source is freely distributable\n",
247 | "- Keeps costs down for scientists and universities operating under a limited budget\n",
248 | "- Frees programmers from licensing concerns for any software they may develop"
249 | ]
250 | },
251 | {
252 | "cell_type": "markdown",
253 | "metadata": {
254 | "nbpresent": {
255 | "id": "5f237cbd-7cd5-40fe-9dc9-5881a440ca56"
256 | },
257 | "slideshow": {
258 | "slide_type": "slide"
259 | }
260 | },
261 | "source": [
262 | "# Setup\n",
263 | "\n",
264 | "## Python 2 vs 3\n",
265 | "A [debate](https://wiki.python.org/moin/Python2orPython3) as old as time. Don't worry about it, just use Python 3 for now.\n",
266 | "\n",
267 | "## The Anaconda Distribution\n",
268 | "[Anaconda](https://www.continuum.io/anaconda-overview) is a suite of tools for Python (and R...) that will install everything you need to get up and running with Python"
269 | ]
270 | },
271 | {
272 | "cell_type": "markdown",
273 | "metadata": {
274 | "nbpresent": {
275 | "id": "36b34ce8-261e-4423-9dd7-8f7ddb66c79b"
276 | },
277 | "slideshow": {
278 | "slide_type": "slide"
279 | }
280 | },
281 | "source": [
282 | "## Python interpreter\n",
283 | "\n",
284 | "- Simply typing `python` at the command line will open up the standard Python interpreter:\n",
285 | "
\n",
286 | "- Seldom used interactively - but we'll use it a lot for running completed programs, e.g.\n",
287 | " \n",
288 | " `python my-program.py`\n"
289 | ]
290 | },
291 | {
292 | "cell_type": "markdown",
293 | "metadata": {
294 | "nbpresent": {
295 | "id": "834c0a44-4d7e-4fb3-9fa9-d0f4262a8e61"
296 | },
297 | "slideshow": {
298 | "slide_type": "slide"
299 | }
300 | },
301 | "source": [
302 | "## IPython\n",
303 | "\n",
304 | "IPython is an interactive interpreter for Python that adds many user-friendly features on top of the standard `python`:\n",
305 | "\n",
306 | "- Tab auto-completion\n",
307 | "- Command history (using up and down arrows)\n",
308 | "- In-line highlighting and editing of code\n",
309 | "- Object introspection\n",
310 | "- Automatic extraction of docstrings from Python objects like classes and functions\n",
311 | "\n",
312 | "Start IPython by simply calling `ipython` from the command line:\n",
313 | "\n",
314 | "
"
315 | ]
316 | },
317 | {
318 | "cell_type": "markdown",
319 | "metadata": {
320 | "nbpresent": {
321 | "id": "33186ec3-970a-433d-a2c9-0bcb5da35ca9"
322 | },
323 | "slideshow": {
324 | "slide_type": "slide"
325 | }
326 | },
327 | "source": [
328 | "## Jupyter\n",
329 | "\n",
330 | "- [Jupyter notebooks](http://jupyter.org/) are HTML-based environments for IPython, R, and more, which allow you to interactively code, explore your data, and integrate documentation\n",
331 | "- *This* is a Jupyter notebook\n",
332 | "- Starting a Jupyter notebook server will launch a local webserver that you can view in your browser to create, view, and run notebooks:\n",
333 | " \n",
334 | " jupyter notebook\n",
335 | " \n",
336 | "
"
337 | ]
338 | },
339 | {
340 | "cell_type": "markdown",
341 | "metadata": {
342 | "nbpresent": {
343 | "id": "a521a6ed-dbc0-4822-8df3-1f3c0caba522"
344 | },
345 | "slideshow": {
346 | "slide_type": "slide"
347 | }
348 | },
349 | "source": [
350 | "## Spyder\n",
351 | "\n",
352 | "- [Spyder](http://code.google.com/p/spyderlib/) is a MATLAB-like IDE for scientific computing with Python\n",
353 | "- Everything from code editing, execution and debugging is carried out in a single environment, and work on different calculations can be organized as projects in the IDE environment\n",
354 | "- Calling Spyder will open up a new project\n",
355 | "\n",
356 | " spyder\n",
357 | " \n",
358 | "
\n",
359 | "\n",
360 | "Another interesting new IDE for Python is [Rodeo](https://www.yhat.com/products/rodeo)"
361 | ]
362 | },
363 | {
364 | "cell_type": "markdown",
365 | "metadata": {
366 | "nbpresent": {
367 | "id": "18b1b9f6-dac6-4bc2-9ff8-c776049d56ab"
368 | },
369 | "slideshow": {
370 | "slide_type": "slide"
371 | }
372 | },
373 | "source": [
374 | "## Installation\n",
375 | "\n",
376 | "### The easy way\n",
377 | "Go to the [Anaconda download page](https://www.continuum.io/downloads) and download the installer for Python 3.5 (64-bit) and simply click through to follow the instructions\n",
378 | "\n",
379 | "### The fancy way\n",
380 | "If you'd like to setup a [Docker container with Anaconda](https://www.continuum.io/blog/developer-blog/anaconda-and-docker-better-together-reproducible-data-science), check out the [Docker setup instructions](../Docker-Instructions.rst). But be warned that it doesn't play terribly nicely with Windows 7 or 8..."
381 | ]
382 | },
383 | {
384 | "cell_type": "markdown",
385 | "metadata": {
386 | "slideshow": {
387 | "slide_type": "slide"
388 | }
389 | },
390 | "source": [
391 | "## Slideshows\n",
392 | "If you'd like to be able to view these notebooks in slideshow mode, install [RISE](https://github.com/damianavila/RISE)\n",
393 | " \n",
394 | " conda install -c damianavila82 rise"
395 | ]
396 | },
397 | {
398 | "cell_type": "code",
399 | "execution_count": 1,
400 | "metadata": {
401 | "collapsed": false,
402 | "slideshow": {
403 | "slide_type": "slide"
404 | }
405 | },
406 | "outputs": [
407 | {
408 | "data": {
409 | "text/markdown": [
410 | "# Exercise 1\n",
411 | "\n",
412 | "## Installing Anaconda\n",
413 | "\n",
414 | "See [the README](../README.rst) for instructions on how to install Anaconda\n",
415 | "on your system.\n",
416 | "\n",
417 | "\n",
418 | "## Clone this repo\n",
419 | "See [the README](../README.rst) again for instructions on cloning this repo\n",
420 | "(into its recommended location of `~/repos/`).\n",
421 | "\n",
422 | "\n",
423 | "## Opening the `python` interpreter\n",
424 | "\n",
425 | "- Open up your terminal and type `python` at the command line\n",
426 | "- Try typing some things in to see how they work... some suggestions:\n",
427 | " * `1 + 1`\n",
428 | " * `1.0 + 1`\n",
429 | " * `\"hello world\"`\n",
430 | " * `print(\"hello world\")`\n",
431 | "- Type `exit()` to exit\n",
432 | "\n",
433 | "\n",
434 | "## Running `ipython`\n",
435 | "\n",
436 | "- Open up the interactive IPython interpreter\n",
437 | " * `ipython`\n",
438 | "- Try some of the same inputs as above\n",
439 | "- Type `print?` and hit `return`\n",
440 | "- Type `print(` and hit `tab`\n",
441 | "- Type `exit()` to exit\n",
442 | "\n",
443 | "\n",
444 | "## Exploring `jupyter notebook`\n",
445 | "\n",
446 | "- Open up a terminal and navigate to the root directory of this repo (e.g. \n",
447 | " `~/repos/ihme-python-course`)\n",
448 | "- Type `jupyter notebook` to startup a notebook server\n",
449 | "- Your web browser will most likely automatically open \n",
450 | " * If not, you can navigate to \n",
451 | " [http://localhost:8888/](http://localhost:8888/)\n",
452 | " * _Note_: if you're already running something on port `8888` it might start\n",
453 | " the server on a different port. Look for a message in your terminal \n",
454 | " like\n",
455 | " The Jupyter Notebook is running at: http://localhost:8889/\n",
456 | " to find it.\n",
457 | "- Use the file tree to navigate to the `Lecture 1/Exercise 1` directory and \n",
458 | " and then click on `test-notebook.ipynb` to open it\n",
459 | "- Follow the instructions in the notebook\n",
460 | "\n",
461 | "\n",
462 | "## Run a script from the command line\n",
463 | "\n",
464 | "- Examine [Exercise 1/test-script.py](Exercise 1/test-script.py) with your\n",
465 | " favorite editor or Spyder\n",
466 | "- Run it from the command line\n",
467 | " * _Hint_: remember `python my-script.py`\n",
468 | "- Change the message from \"hello world\" to something else and execute it\n",
469 | "\n",
470 | "\n",
471 | "## _Optional_: Install `RISE`\n",
472 | "\n",
473 | "- [`RISE`](https://github.com/damianavila/RISE) will add a new button to your\n",
474 | " Jupyter toolbar that'll allow you to view these notebooks in slideshow mode\n",
475 | "- Click the new bargraph-esque icon in the toolbar to start a slideshow\n",
476 | "- Use `spacebar` and `shift+spacebar` to navigate through the slides\n",
477 | "- To edit how the slideshow is structured, take a look at \n",
478 | " `View > Cell Toolbar > Slideshow`\n"
479 | ],
480 | "text/plain": [
481 | ""
482 | ]
483 | },
484 | "metadata": {},
485 | "output_type": "display_data"
486 | }
487 | ],
488 | "source": [
489 | "from IPython.display import Markdown, display\n",
490 | "display(Markdown(open('./Exercise 1/README.md', 'r').read()))"
491 | ]
492 | },
493 | {
494 | "cell_type": "markdown",
495 | "metadata": {
496 | "nbpresent": {
497 | "id": "8ea66e52-ab66-4ea4-841c-5f4be654c984"
498 | },
499 | "slideshow": {
500 | "slide_type": "slide"
501 | }
502 | },
503 | "source": [
504 | "# References\n",
505 | "\n",
506 | "- Slide materials inspired by and adapted from [Chris Fonnesbeck](https://github.com/fonnesbeck/HealthPolicyPython) and [J Robert Johansson](https://github.com/jrjohansson/scientific-python-lectures)"
507 | ]
508 | }
509 | ],
510 | "metadata": {
511 | "anaconda-cloud": {},
512 | "kernelspec": {
513 | "display_name": "Python [conda root]",
514 | "language": "python",
515 | "name": "conda-root-py"
516 | },
517 | "language_info": {
518 | "codemirror_mode": {
519 | "name": "ipython",
520 | "version": 3
521 | },
522 | "file_extension": ".py",
523 | "mimetype": "text/x-python",
524 | "name": "python",
525 | "nbconvert_exporter": "python",
526 | "pygments_lexer": "ipython3",
527 | "version": "3.5.2"
528 | },
529 | "livereveal": {
530 | "height": 768,
531 | "scroll": true,
532 | "slideNumber": true,
533 | "start_slideshow_at": "selected",
534 | "theme": "league",
535 | "width": 1024
536 | }
537 | },
538 | "nbformat": 4,
539 | "nbformat_minor": 0
540 | }
541 |
--------------------------------------------------------------------------------
/Lecture 1/imgs/ipython.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 1/imgs/ipython.png
--------------------------------------------------------------------------------
/Lecture 1/imgs/jupyter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 1/imgs/jupyter.png
--------------------------------------------------------------------------------
/Lecture 1/imgs/python.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 1/imgs/python.png
--------------------------------------------------------------------------------
/Lecture 1/imgs/spyder.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 1/imgs/spyder.png
--------------------------------------------------------------------------------
/Lecture 2/Exercise 2 - Solutions.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Exercise 2"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "### Part 1 - Lists"
15 | ]
16 | },
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {},
20 | "source": [
21 | "Use a loop to make a list of the integers from 5 to 10"
22 | ]
23 | },
24 | {
25 | "cell_type": "code",
26 | "execution_count": 1,
27 | "metadata": {
28 | "collapsed": false
29 | },
30 | "outputs": [
31 | {
32 | "data": {
33 | "text/plain": [
34 | "[5, 6, 7, 8, 9, 10]"
35 | ]
36 | },
37 | "execution_count": 1,
38 | "metadata": {},
39 | "output_type": "execute_result"
40 | }
41 | ],
42 | "source": [
43 | "int_list = []\n",
44 | "for i in range(5,11):\n",
45 | " int_list.append(i)\n",
46 | "int_list"
47 | ]
48 | },
49 | {
50 | "cell_type": "markdown",
51 | "metadata": {},
52 | "source": [
53 | "Use a list comprehension to make a list of the integers from 20 to 30"
54 | ]
55 | },
56 | {
57 | "cell_type": "code",
58 | "execution_count": 2,
59 | "metadata": {
60 | "collapsed": false
61 | },
62 | "outputs": [
63 | {
64 | "data": {
65 | "text/plain": [
66 | "[20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]"
67 | ]
68 | },
69 | "execution_count": 2,
70 | "metadata": {},
71 | "output_type": "execute_result"
72 | }
73 | ],
74 | "source": [
75 | "int_list_2 = [i for i in range(20,31)]\n",
76 | "int_list_2"
77 | ]
78 | },
79 | {
80 | "cell_type": "markdown",
81 | "metadata": {},
82 | "source": [
83 | "Print just the 3rd, 4th, and 5th integers in that array"
84 | ]
85 | },
86 | {
87 | "cell_type": "code",
88 | "execution_count": 3,
89 | "metadata": {
90 | "collapsed": false
91 | },
92 | "outputs": [
93 | {
94 | "name": "stdout",
95 | "output_type": "stream",
96 | "text": [
97 | "[22, 23, 24]\n"
98 | ]
99 | }
100 | ],
101 | "source": [
102 | "print(int_list_2[2:5])"
103 | ]
104 | },
105 | {
106 | "cell_type": "markdown",
107 | "metadata": {},
108 | "source": [
109 | "### Part 2 - Dictionaries and functions"
110 | ]
111 | },
112 | {
113 | "cell_type": "markdown",
114 | "metadata": {},
115 | "source": [
116 | "Make a dictionary that contains the number of characters for each word in a list\n",
117 | "\n",
118 | "E.g.\n",
119 | " \n",
120 | " ['hello', 'world!'] -> {'hello': 5, 'world!': 6}"
121 | ]
122 | },
123 | {
124 | "cell_type": "code",
125 | "execution_count": 4,
126 | "metadata": {
127 | "collapsed": true
128 | },
129 | "outputs": [],
130 | "source": [
131 | "word_list = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']"
132 | ]
133 | },
134 | {
135 | "cell_type": "code",
136 | "execution_count": 5,
137 | "metadata": {
138 | "collapsed": false
139 | },
140 | "outputs": [
141 | {
142 | "name": "stdout",
143 | "output_type": "stream",
144 | "text": [
145 | "{'Mercury': 7, 'Mars': 4, 'Neptune': 7, 'Saturn': 6, 'Uranus': 6, 'Earth': 5, 'Jupiter': 7, 'Venus': 5}\n"
146 | ]
147 | }
148 | ],
149 | "source": [
150 | "num_chars = {}\n",
151 | "for w in word_list:\n",
152 | " num_chars[w] = len(w)\n",
153 | "print(num_chars)"
154 | ]
155 | },
156 | {
157 | "cell_type": "markdown",
158 | "metadata": {},
159 | "source": [
160 | "Add poor Pluto back to the list"
161 | ]
162 | },
163 | {
164 | "cell_type": "code",
165 | "execution_count": 6,
166 | "metadata": {
167 | "collapsed": false
168 | },
169 | "outputs": [
170 | {
171 | "data": {
172 | "text/plain": [
173 | "['Mercury',\n",
174 | " 'Venus',\n",
175 | " 'Earth',\n",
176 | " 'Mars',\n",
177 | " 'Jupiter',\n",
178 | " 'Saturn',\n",
179 | " 'Uranus',\n",
180 | " 'Neptune',\n",
181 | " 'Pluto']"
182 | ]
183 | },
184 | "execution_count": 6,
185 | "metadata": {},
186 | "output_type": "execute_result"
187 | }
188 | ],
189 | "source": [
190 | "word_list.append('Pluto')\n",
191 | "word_list"
192 | ]
193 | },
194 | {
195 | "cell_type": "markdown",
196 | "metadata": {},
197 | "source": [
198 | "Now try to make up the lookup for the number of characters using a comprehension instead of a loop"
199 | ]
200 | },
201 | {
202 | "cell_type": "code",
203 | "execution_count": 7,
204 | "metadata": {
205 | "collapsed": false
206 | },
207 | "outputs": [
208 | {
209 | "data": {
210 | "text/plain": [
211 | "{'Earth': 5,\n",
212 | " 'Jupiter': 7,\n",
213 | " 'Mars': 4,\n",
214 | " 'Mercury': 7,\n",
215 | " 'Neptune': 7,\n",
216 | " 'Pluto': 5,\n",
217 | " 'Saturn': 6,\n",
218 | " 'Uranus': 6,\n",
219 | " 'Venus': 5}"
220 | ]
221 | },
222 | "execution_count": 7,
223 | "metadata": {},
224 | "output_type": "execute_result"
225 | }
226 | ],
227 | "source": [
228 | "dict_comprehension = {w: len(w) for w in word_list}\n",
229 | "dict_comprehension"
230 | ]
231 | },
232 | {
233 | "cell_type": "markdown",
234 | "metadata": {},
235 | "source": [
236 | "Count the total number of characters in the list using a loop"
237 | ]
238 | },
239 | {
240 | "cell_type": "code",
241 | "execution_count": 8,
242 | "metadata": {
243 | "collapsed": false
244 | },
245 | "outputs": [
246 | {
247 | "name": "stdout",
248 | "output_type": "stream",
249 | "text": [
250 | "52\n"
251 | ]
252 | }
253 | ],
254 | "source": [
255 | "total = 0\n",
256 | "for w in word_list:\n",
257 | " total += dict_comprehension[w]\n",
258 | "print(total)"
259 | ]
260 | },
261 | {
262 | "cell_type": "markdown",
263 | "metadata": {},
264 | "source": [
265 | "Can you count the total number of characters using just `dict_comprehension` and no loops?"
266 | ]
267 | },
268 | {
269 | "cell_type": "markdown",
270 | "metadata": {},
271 | "source": [
272 | "_Hint_: Inspect the `dict_comprehension` object - does it contain any methods or properties that might help you?"
273 | ]
274 | },
275 | {
276 | "cell_type": "code",
277 | "execution_count": 9,
278 | "metadata": {
279 | "collapsed": false
280 | },
281 | "outputs": [
282 | {
283 | "data": {
284 | "text/plain": [
285 | "['__class__',\n",
286 | " '__contains__',\n",
287 | " '__delattr__',\n",
288 | " '__delitem__',\n",
289 | " '__dir__',\n",
290 | " '__doc__',\n",
291 | " '__eq__',\n",
292 | " '__format__',\n",
293 | " '__ge__',\n",
294 | " '__getattribute__',\n",
295 | " '__getitem__',\n",
296 | " '__gt__',\n",
297 | " '__hash__',\n",
298 | " '__init__',\n",
299 | " '__iter__',\n",
300 | " '__le__',\n",
301 | " '__len__',\n",
302 | " '__lt__',\n",
303 | " '__ne__',\n",
304 | " '__new__',\n",
305 | " '__reduce__',\n",
306 | " '__reduce_ex__',\n",
307 | " '__repr__',\n",
308 | " '__setattr__',\n",
309 | " '__setitem__',\n",
310 | " '__sizeof__',\n",
311 | " '__str__',\n",
312 | " '__subclasshook__',\n",
313 | " 'clear',\n",
314 | " 'copy',\n",
315 | " 'fromkeys',\n",
316 | " 'get',\n",
317 | " 'items',\n",
318 | " 'keys',\n",
319 | " 'pop',\n",
320 | " 'popitem',\n",
321 | " 'setdefault',\n",
322 | " 'update',\n",
323 | " 'values']"
324 | ]
325 | },
326 | "execution_count": 9,
327 | "metadata": {},
328 | "output_type": "execute_result"
329 | }
330 | ],
331 | "source": [
332 | "dir(dict_comprehension)"
333 | ]
334 | },
335 | {
336 | "cell_type": "code",
337 | "execution_count": 10,
338 | "metadata": {
339 | "collapsed": false
340 | },
341 | "outputs": [
342 | {
343 | "data": {
344 | "text/plain": [
345 | "52"
346 | ]
347 | },
348 | "execution_count": 10,
349 | "metadata": {},
350 | "output_type": "execute_result"
351 | }
352 | ],
353 | "source": [
354 | "sum(dict_comprehension.values())"
355 | ]
356 | },
357 | {
358 | "cell_type": "markdown",
359 | "metadata": {},
360 | "source": [
361 | "### Part 3 - Factors\n",
362 | "\n",
363 | "Design a function which returns a list containing all of the [factors](https://en.wikipedia.org/wiki/Integer_factorization) of an integer\n",
364 | "\n",
365 | "E.g.: \n",
366 | "\n",
367 | " 10 -> [1, 2, 5, 10]\n",
368 | " 50 -> [1, 2, 5, 10, 25, 50]"
369 | ]
370 | },
371 | {
372 | "cell_type": "code",
373 | "execution_count": 11,
374 | "metadata": {
375 | "collapsed": true
376 | },
377 | "outputs": [],
378 | "source": [
379 | "def factors(n):\n",
380 | " ''' Return a list containing the factors for integer n '''\n",
381 | " fac = []\n",
382 | " for i in range(1,n+1):\n",
383 | " if n % i == 0:\n",
384 | " fac.append(i)\n",
385 | " return fac"
386 | ]
387 | },
388 | {
389 | "cell_type": "code",
390 | "execution_count": 12,
391 | "metadata": {
392 | "collapsed": false
393 | },
394 | "outputs": [
395 | {
396 | "data": {
397 | "text/plain": [
398 | "[1, 2, 5, 10]"
399 | ]
400 | },
401 | "execution_count": 12,
402 | "metadata": {},
403 | "output_type": "execute_result"
404 | }
405 | ],
406 | "source": [
407 | "factors(10)"
408 | ]
409 | },
410 | {
411 | "cell_type": "markdown",
412 | "metadata": {},
413 | "source": [
414 | "**Bonus**: Can you do it in one line?"
415 | ]
416 | },
417 | {
418 | "cell_type": "code",
419 | "execution_count": 13,
420 | "metadata": {
421 | "collapsed": true
422 | },
423 | "outputs": [],
424 | "source": [
425 | "def one_line_factors(n):\n",
426 | " ''' Return a list containing the factors for integer n '''\n",
427 | " return [i for i in range(1,n+1) if n % i == 0]"
428 | ]
429 | },
430 | {
431 | "cell_type": "code",
432 | "execution_count": 14,
433 | "metadata": {
434 | "collapsed": false
435 | },
436 | "outputs": [
437 | {
438 | "data": {
439 | "text/plain": [
440 | "[1, 2, 5, 10]"
441 | ]
442 | },
443 | "execution_count": 14,
444 | "metadata": {},
445 | "output_type": "execute_result"
446 | }
447 | ],
448 | "source": [
449 | "one_line_factors(10)"
450 | ]
451 | },
452 | {
453 | "cell_type": "markdown",
454 | "metadata": {},
455 | "source": [
456 | "### Part 4 - Fibonacci Sequence\n",
457 | "\n",
458 | "Create a function which will return the first `n` numbers in the [Fibonacci sequence](https://en.wikipedia.org/wiki/Fibonacci_number) starting at 1 (1, 1, 2, 3, 5, 8, 13, ...)"
459 | ]
460 | },
461 | {
462 | "cell_type": "code",
463 | "execution_count": 15,
464 | "metadata": {
465 | "collapsed": true
466 | },
467 | "outputs": [],
468 | "source": [
469 | "def fib(n):\n",
470 | " ''' Return the first n digits of the Fibonacci sequence '''\n",
471 | " seq = [1,1]\n",
472 | " while len(seq) < n:\n",
473 | " seq.append(seq[-1] + seq[-2])\n",
474 | " return seq"
475 | ]
476 | },
477 | {
478 | "cell_type": "code",
479 | "execution_count": 16,
480 | "metadata": {
481 | "collapsed": false
482 | },
483 | "outputs": [
484 | {
485 | "data": {
486 | "text/plain": [
487 | "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55]"
488 | ]
489 | },
490 | "execution_count": 16,
491 | "metadata": {},
492 | "output_type": "execute_result"
493 | }
494 | ],
495 | "source": [
496 | "fib(10)"
497 | ]
498 | },
499 | {
500 | "cell_type": "code",
501 | "execution_count": 17,
502 | "metadata": {
503 | "collapsed": false
504 | },
505 | "outputs": [],
506 | "source": [
507 | "assert fib(10)[-1] == 55"
508 | ]
509 | },
510 | {
511 | "cell_type": "markdown",
512 | "metadata": {},
513 | "source": [
514 | "**Bonus**: Design a function that creates a simple \"graph\" of the Fibonacci sequence\n",
515 | "\n",
516 | "e.g.\n",
517 | "```\n",
518 | "#\n",
519 | "#\n",
520 | "##\n",
521 | "###\n",
522 | "#####\n",
523 | "########\n",
524 | "#############\n",
525 | "```\n",
526 | "\n",
527 | "_Hint_: What happens if you multiply a `string`?"
528 | ]
529 | },
530 | {
531 | "cell_type": "code",
532 | "execution_count": 18,
533 | "metadata": {
534 | "collapsed": false
535 | },
536 | "outputs": [],
537 | "source": [
538 | "def fib_graph(n):\n",
539 | " ''' Draw a graph of the first n digits of the Fibonacci sequence '''\n",
540 | " seq = fib(n)\n",
541 | " for i in seq:\n",
542 | " print('#' * i)"
543 | ]
544 | },
545 | {
546 | "cell_type": "code",
547 | "execution_count": 19,
548 | "metadata": {
549 | "collapsed": false
550 | },
551 | "outputs": [
552 | {
553 | "name": "stdout",
554 | "output_type": "stream",
555 | "text": [
556 | "#\n",
557 | "#\n",
558 | "##\n",
559 | "###\n",
560 | "#####\n",
561 | "########\n",
562 | "#############\n",
563 | "#####################\n",
564 | "##################################\n",
565 | "#######################################################\n"
566 | ]
567 | }
568 | ],
569 | "source": [
570 | "fib_graph(10)"
571 | ]
572 | },
573 | {
574 | "cell_type": "code",
575 | "execution_count": 20,
576 | "metadata": {
577 | "collapsed": false
578 | },
579 | "outputs": [
580 | {
581 | "name": "stdout",
582 | "output_type": "stream",
583 | "text": [
584 | "#\n",
585 | "#\n",
586 | "##\n",
587 | "###\n",
588 | "#####\n",
589 | "########\n",
590 | "#############\n",
591 | "#####################\n",
592 | "##################################\n",
593 | "#######################################################\n"
594 | ]
595 | }
596 | ],
597 | "source": [
598 | "def alt_fib_graph(n):\n",
599 | " ''' Draw a graph of the first n digits of the Fibonacci sequence '''\n",
600 | " seq = fib(n)\n",
601 | " return '\\n'.join([''.join(['#' for i in range(x)]) for x in seq])\n",
602 | "print(alt_fib_graph(10))"
603 | ]
604 | },
605 | {
606 | "cell_type": "markdown",
607 | "metadata": {},
608 | "source": [
609 | "__Super Bonus__: Can you create a Fibonacci [`class`](https://docs.python.org/3/tutorial/classes.html) which calculates the sequence of order `n`, stores it, and can print it as a graph?"
610 | ]
611 | },
612 | {
613 | "cell_type": "code",
614 | "execution_count": 21,
615 | "metadata": {
616 | "collapsed": true
617 | },
618 | "outputs": [],
619 | "source": [
620 | "class Fibonacci():\n",
621 | " ''' Creates the Fibonacci sequence of order n, both storing it and making graphs of it '''\n",
622 | "\n",
623 | " def __init__(self, n, graph_it=False):\n",
624 | " ''' Initialize the sequence by storing n, and then calculating the sequence '''\n",
625 | " self.n = n\n",
626 | " self.calculate()\n",
627 | " if graph_it:\n",
628 | " self.graph()\n",
629 | " \n",
630 | " def calculate(self):\n",
631 | " ''' Calculate the Fibonacci sequence of order n and store it in self.seq '''\n",
632 | " seq = [1,1]\n",
633 | " while len(seq) < self.n:\n",
634 | " seq.append(seq[-1] + seq[-2])\n",
635 | " self.seq = seq\n",
636 | " \n",
637 | " def graph(self):\n",
638 | " ''' Print a graph of the Fibonacci sequence '''\n",
639 | " for i in self.seq:\n",
640 | " print('#' * i)"
641 | ]
642 | },
643 | {
644 | "cell_type": "code",
645 | "execution_count": 22,
646 | "metadata": {
647 | "collapsed": true
648 | },
649 | "outputs": [],
650 | "source": [
651 | "fib11 = Fibonacci(11)"
652 | ]
653 | },
654 | {
655 | "cell_type": "code",
656 | "execution_count": 23,
657 | "metadata": {
658 | "collapsed": false
659 | },
660 | "outputs": [
661 | {
662 | "data": {
663 | "text/plain": [
664 | "[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]"
665 | ]
666 | },
667 | "execution_count": 23,
668 | "metadata": {},
669 | "output_type": "execute_result"
670 | }
671 | ],
672 | "source": [
673 | "fib11.seq"
674 | ]
675 | },
676 | {
677 | "cell_type": "code",
678 | "execution_count": 24,
679 | "metadata": {
680 | "collapsed": false
681 | },
682 | "outputs": [
683 | {
684 | "name": "stdout",
685 | "output_type": "stream",
686 | "text": [
687 | "#\n",
688 | "#\n",
689 | "##\n",
690 | "###\n",
691 | "#####\n",
692 | "########\n",
693 | "#############\n",
694 | "#####################\n",
695 | "##################################\n",
696 | "#######################################################\n",
697 | "#########################################################################################\n"
698 | ]
699 | }
700 | ],
701 | "source": [
702 | "fib11.graph()"
703 | ]
704 | },
705 | {
706 | "cell_type": "code",
707 | "execution_count": 25,
708 | "metadata": {
709 | "collapsed": false
710 | },
711 | "outputs": [
712 | {
713 | "name": "stdout",
714 | "output_type": "stream",
715 | "text": [
716 | "#\n",
717 | "#\n",
718 | "##\n",
719 | "###\n",
720 | "#####\n",
721 | "########\n",
722 | "#############\n",
723 | "#####################\n"
724 | ]
725 | }
726 | ],
727 | "source": [
728 | "fib8 = Fibonacci(8, graph_it=True)"
729 | ]
730 | }
731 | ],
732 | "metadata": {
733 | "anaconda-cloud": {},
734 | "kernelspec": {
735 | "display_name": "Python [conda root]",
736 | "language": "python",
737 | "name": "conda-root-py"
738 | },
739 | "language_info": {
740 | "codemirror_mode": {
741 | "name": "ipython",
742 | "version": 3
743 | },
744 | "file_extension": ".py",
745 | "mimetype": "text/x-python",
746 | "name": "python",
747 | "nbconvert_exporter": "python",
748 | "pygments_lexer": "ipython3",
749 | "version": "3.5.2"
750 | }
751 | },
752 | "nbformat": 4,
753 | "nbformat_minor": 1
754 | }
755 |
--------------------------------------------------------------------------------
/Lecture 2/Exercise 2.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Exercise 2"
8 | ]
9 | },
10 | {
11 | "cell_type": "markdown",
12 | "metadata": {},
13 | "source": [
14 | "### Part 1 - Lists"
15 | ]
16 | },
17 | {
18 | "cell_type": "markdown",
19 | "metadata": {},
20 | "source": [
21 | "Use a loop to make a list of the integers from 5 to 10"
22 | ]
23 | },
24 | {
25 | "cell_type": "code",
26 | "execution_count": null,
27 | "metadata": {
28 | "collapsed": false
29 | },
30 | "outputs": [],
31 | "source": [
32 | "int_list = []\n",
33 | "for i in range(1):\n",
34 | " int_list.append(i)\n",
35 | "int_list"
36 | ]
37 | },
38 | {
39 | "cell_type": "markdown",
40 | "metadata": {},
41 | "source": [
42 | "Use a list comprehension to make a list of the integers from 20 to 30"
43 | ]
44 | },
45 | {
46 | "cell_type": "code",
47 | "execution_count": null,
48 | "metadata": {
49 | "collapsed": false
50 | },
51 | "outputs": [],
52 | "source": [
53 | "int_list_2 = []\n",
54 | "int_list_2"
55 | ]
56 | },
57 | {
58 | "cell_type": "markdown",
59 | "metadata": {},
60 | "source": [
61 | "Print just the 3rd, 4th, and 5th integers in that array"
62 | ]
63 | },
64 | {
65 | "cell_type": "code",
66 | "execution_count": null,
67 | "metadata": {
68 | "collapsed": false
69 | },
70 | "outputs": [],
71 | "source": [
72 | "print(int_list_2)"
73 | ]
74 | },
75 | {
76 | "cell_type": "markdown",
77 | "metadata": {},
78 | "source": [
79 | "### Part 2 - Dictionaries and functions"
80 | ]
81 | },
82 | {
83 | "cell_type": "markdown",
84 | "metadata": {},
85 | "source": [
86 | "Make a dictionary that contains the number of characters for each word in a list\n",
87 | "\n",
88 | "E.g.\n",
89 | " \n",
90 | " ['hello', 'world!'] -> {'hello': 5, 'world!': 6}"
91 | ]
92 | },
93 | {
94 | "cell_type": "code",
95 | "execution_count": null,
96 | "metadata": {
97 | "collapsed": true
98 | },
99 | "outputs": [],
100 | "source": [
101 | "word_list = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']"
102 | ]
103 | },
104 | {
105 | "cell_type": "code",
106 | "execution_count": null,
107 | "metadata": {
108 | "collapsed": false
109 | },
110 | "outputs": [],
111 | "source": [
112 | "num_chars = {}\n",
113 | "for w in word_list:\n",
114 | " pass\n",
115 | "print(num_chars)"
116 | ]
117 | },
118 | {
119 | "cell_type": "markdown",
120 | "metadata": {},
121 | "source": [
122 | "Add poor Pluto back to the list"
123 | ]
124 | },
125 | {
126 | "cell_type": "code",
127 | "execution_count": null,
128 | "metadata": {
129 | "collapsed": false
130 | },
131 | "outputs": [],
132 | "source": [
133 | "word_list"
134 | ]
135 | },
136 | {
137 | "cell_type": "markdown",
138 | "metadata": {},
139 | "source": [
140 | "Now try to make up the lookup for the number of characters using a comprehension instead of a loop"
141 | ]
142 | },
143 | {
144 | "cell_type": "code",
145 | "execution_count": null,
146 | "metadata": {
147 | "collapsed": false
148 | },
149 | "outputs": [],
150 | "source": [
151 | "dict_comprehension = {}\n",
152 | "dict_comprehension"
153 | ]
154 | },
155 | {
156 | "cell_type": "markdown",
157 | "metadata": {},
158 | "source": [
159 | "Count the total number of characters in the list using a loop"
160 | ]
161 | },
162 | {
163 | "cell_type": "code",
164 | "execution_count": null,
165 | "metadata": {
166 | "collapsed": false
167 | },
168 | "outputs": [],
169 | "source": [
170 | "total = 0\n",
171 | "for w in word_list:\n",
172 | " pass\n",
173 | "print(total)"
174 | ]
175 | },
176 | {
177 | "cell_type": "markdown",
178 | "metadata": {},
179 | "source": [
180 | "Can you count the total number of characters using just `dict_comprehension` and no loops?"
181 | ]
182 | },
183 | {
184 | "cell_type": "code",
185 | "execution_count": null,
186 | "metadata": {
187 | "collapsed": false
188 | },
189 | "outputs": [],
190 | "source": [
191 | "sum([])"
192 | ]
193 | },
194 | {
195 | "cell_type": "markdown",
196 | "metadata": {},
197 | "source": [
198 | "_Hint_: Inspect the `dict_comprehension` object - does it contain any methods or properties that might help you?"
199 | ]
200 | },
201 | {
202 | "cell_type": "markdown",
203 | "metadata": {},
204 | "source": [
205 | "### Part 3 - Factors\n",
206 | "\n",
207 | "Design a function which returns a list containing all of the [factors](https://en.wikipedia.org/wiki/Integer_factorization) of an integer\n",
208 | "\n",
209 | "E.g.: \n",
210 | "\n",
211 | " 10 -> [1, 2, 5, 10]\n",
212 | " 50 -> [1, 2, 5, 10, 25, 50]"
213 | ]
214 | },
215 | {
216 | "cell_type": "code",
217 | "execution_count": null,
218 | "metadata": {
219 | "collapsed": true
220 | },
221 | "outputs": [],
222 | "source": [
223 | "def factors(n):\n",
224 | " ''' Return a list containing the factors for integer n '''\n",
225 | " fac = []\n",
226 | " return fac"
227 | ]
228 | },
229 | {
230 | "cell_type": "code",
231 | "execution_count": null,
232 | "metadata": {
233 | "collapsed": false
234 | },
235 | "outputs": [],
236 | "source": [
237 | "factors(10)"
238 | ]
239 | },
240 | {
241 | "cell_type": "markdown",
242 | "metadata": {},
243 | "source": [
244 | "**Bonus**: Can you do it in one line?"
245 | ]
246 | },
247 | {
248 | "cell_type": "code",
249 | "execution_count": null,
250 | "metadata": {
251 | "collapsed": true
252 | },
253 | "outputs": [],
254 | "source": [
255 | "def one_line_factors(n):\n",
256 | " ''' Return a list containing the factors for integer n '''\n",
257 | " pass"
258 | ]
259 | },
260 | {
261 | "cell_type": "code",
262 | "execution_count": null,
263 | "metadata": {
264 | "collapsed": false
265 | },
266 | "outputs": [],
267 | "source": [
268 | "one_line_factors(10)"
269 | ]
270 | },
271 | {
272 | "cell_type": "markdown",
273 | "metadata": {},
274 | "source": [
275 | "### Part 4 - Fibonacci Sequence\n",
276 | "\n",
277 | "Create a function which will return the first `n` numbers in the [Fibonacci sequence](https://en.wikipedia.org/wiki/Fibonacci_number) starting at 1 (1, 1, 2, 3, 5, 8, 13, ...)"
278 | ]
279 | },
280 | {
281 | "cell_type": "code",
282 | "execution_count": null,
283 | "metadata": {
284 | "collapsed": true
285 | },
286 | "outputs": [],
287 | "source": [
288 | "def fib(n):\n",
289 | " ''' Return the first n digits of the Fibonacci sequence '''\n",
290 | " seq = []\n",
291 | " return seq"
292 | ]
293 | },
294 | {
295 | "cell_type": "code",
296 | "execution_count": null,
297 | "metadata": {
298 | "collapsed": false
299 | },
300 | "outputs": [],
301 | "source": [
302 | "fib(10)"
303 | ]
304 | },
305 | {
306 | "cell_type": "code",
307 | "execution_count": null,
308 | "metadata": {
309 | "collapsed": false
310 | },
311 | "outputs": [],
312 | "source": [
313 | "assert fib(10)[-1] == 55"
314 | ]
315 | },
316 | {
317 | "cell_type": "markdown",
318 | "metadata": {},
319 | "source": [
320 | "**Bonus**: Design a function that creates a simple \"graph\" of the Fibonacci sequence\n",
321 | "\n",
322 | "e.g.\n",
323 | "```\n",
324 | "#\n",
325 | "#\n",
326 | "##\n",
327 | "###\n",
328 | "#####\n",
329 | "########\n",
330 | "#############\n",
331 | "```\n",
332 | "\n",
333 | "_Hint_: Remember `string.join()?`"
334 | ]
335 | },
336 | {
337 | "cell_type": "code",
338 | "execution_count": null,
339 | "metadata": {
340 | "collapsed": true
341 | },
342 | "outputs": [],
343 | "source": [
344 | "def fib_graph(n):\n",
345 | " ''' Draw a graph of the first n digits of the Fibonacci sequence '''\n",
346 | " seq = fib(n)\n",
347 | " return ''"
348 | ]
349 | },
350 | {
351 | "cell_type": "code",
352 | "execution_count": null,
353 | "metadata": {
354 | "collapsed": false
355 | },
356 | "outputs": [],
357 | "source": [
358 | "print(fib_graph(10))"
359 | ]
360 | },
361 | {
362 | "cell_type": "markdown",
363 | "metadata": {},
364 | "source": [
365 | "__Super Bonus__: Can you create a Fibonacci [`class`](https://docs.python.org/3/tutorial/classes.html) which calculates the sequence of order `n`, stores it, and can print it as a graph?"
366 | ]
367 | },
368 | {
369 | "cell_type": "code",
370 | "execution_count": null,
371 | "metadata": {
372 | "collapsed": true
373 | },
374 | "outputs": [],
375 | "source": [
376 | "class Fibonacci():\n",
377 | " ''' Creates the Fibonacci sequence of order n, both storing it and making graphs of it '''\n",
378 | "\n",
379 | " def __init__(self, n, graph_it=False):\n",
380 | " ''' Initialize the sequence by storing n, and then calculating the sequence '''\n",
381 | " pass\n",
382 | " \n",
383 | " def calculate(self):\n",
384 | " ''' Calculate the Fibonacci sequence of order n and store it in self.seq '''\n",
385 | " pass\n",
386 | " \n",
387 | " def graph(self):\n",
388 | " ''' Print a graph of the Fibonacci sequence '''\n",
389 | " pass"
390 | ]
391 | },
392 | {
393 | "cell_type": "code",
394 | "execution_count": null,
395 | "metadata": {
396 | "collapsed": true
397 | },
398 | "outputs": [],
399 | "source": [
400 | "fib11 = Fibonacci(11)"
401 | ]
402 | },
403 | {
404 | "cell_type": "code",
405 | "execution_count": null,
406 | "metadata": {
407 | "collapsed": false
408 | },
409 | "outputs": [],
410 | "source": [
411 | "fib11.seq"
412 | ]
413 | },
414 | {
415 | "cell_type": "code",
416 | "execution_count": null,
417 | "metadata": {
418 | "collapsed": false
419 | },
420 | "outputs": [],
421 | "source": [
422 | "fib11.graph()"
423 | ]
424 | },
425 | {
426 | "cell_type": "code",
427 | "execution_count": null,
428 | "metadata": {
429 | "collapsed": false
430 | },
431 | "outputs": [],
432 | "source": [
433 | "fib8 = Fibonacci(8, graph_it=True)"
434 | ]
435 | }
436 | ],
437 | "metadata": {
438 | "anaconda-cloud": {},
439 | "kernelspec": {
440 | "display_name": "Python [conda root]",
441 | "language": "python",
442 | "name": "conda-root-py"
443 | },
444 | "language_info": {
445 | "codemirror_mode": {
446 | "name": "ipython",
447 | "version": 3
448 | },
449 | "file_extension": ".py",
450 | "mimetype": "text/x-python",
451 | "name": "python",
452 | "nbconvert_exporter": "python",
453 | "pygments_lexer": "ipython3",
454 | "version": "3.5.2"
455 | }
456 | },
457 | "nbformat": 4,
458 | "nbformat_minor": 1
459 | }
460 |
--------------------------------------------------------------------------------
/Lecture 3/Exercise 3.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Exercise 3\n",
8 | "\n",
9 | "Adapted from Software Carpentry's [Gapminder tutorial](http://swcarpentry.github.io/python-novice-gapminder/08-data-frames/)"
10 | ]
11 | },
12 | {
13 | "cell_type": "markdown",
14 | "metadata": {},
15 | "source": [
16 | "### Part 1"
17 | ]
18 | },
19 | {
20 | "cell_type": "markdown",
21 | "metadata": {},
22 | "source": [
23 | "Load the Gapminder GDP data for Europe into a Pandas DataFrame\n",
24 | "\n",
25 | " data/gapminder_gdp_europe.csv"
26 | ]
27 | },
28 | {
29 | "cell_type": "code",
30 | "execution_count": null,
31 | "metadata": {
32 | "collapsed": true
33 | },
34 | "outputs": [],
35 | "source": [
36 | "import pandas as pd"
37 | ]
38 | },
39 | {
40 | "cell_type": "code",
41 | "execution_count": null,
42 | "metadata": {
43 | "collapsed": false
44 | },
45 | "outputs": [],
46 | "source": [
47 | "df = pd.read_csv?"
48 | ]
49 | },
50 | {
51 | "cell_type": "code",
52 | "execution_count": null,
53 | "metadata": {
54 | "collapsed": false
55 | },
56 | "outputs": [],
57 | "source": [
58 | "df.head()"
59 | ]
60 | },
61 | {
62 | "cell_type": "markdown",
63 | "metadata": {},
64 | "source": [
65 | "Set the `country` name as the index on this dataframe"
66 | ]
67 | },
68 | {
69 | "cell_type": "code",
70 | "execution_count": null,
71 | "metadata": {
72 | "collapsed": false
73 | },
74 | "outputs": [],
75 | "source": [
76 | "df = df\n",
77 | "df.head()"
78 | ]
79 | },
80 | {
81 | "cell_type": "markdown",
82 | "metadata": {},
83 | "source": [
84 | "Instead, add the `country` index during the call to `.read_csv()`\n",
85 | "\n",
86 | "_Hint_: it's one of the first 10 arguments listed by `pd.read_csv?`"
87 | ]
88 | },
89 | {
90 | "cell_type": "code",
91 | "execution_count": null,
92 | "metadata": {
93 | "collapsed": false
94 | },
95 | "outputs": [],
96 | "source": [
97 | "df = pd.read_csv()\n",
98 | "df.head()"
99 | ]
100 | },
101 | {
102 | "cell_type": "markdown",
103 | "metadata": {},
104 | "source": [
105 | "What was the GDP of Serbia in 2007?"
106 | ]
107 | },
108 | {
109 | "cell_type": "code",
110 | "execution_count": null,
111 | "metadata": {
112 | "collapsed": false
113 | },
114 | "outputs": [],
115 | "source": [
116 | "df.loc"
117 | ]
118 | },
119 | {
120 | "cell_type": "markdown",
121 | "metadata": {},
122 | "source": [
123 | "### Part 2"
124 | ]
125 | },
126 | {
127 | "cell_type": "markdown",
128 | "metadata": {},
129 | "source": [
130 | "What's the difference between the two statements below?"
131 | ]
132 | },
133 | {
134 | "cell_type": "code",
135 | "execution_count": null,
136 | "metadata": {
137 | "collapsed": false
138 | },
139 | "outputs": [],
140 | "source": [
141 | "df.iloc[0:2, 0:2]"
142 | ]
143 | },
144 | {
145 | "cell_type": "code",
146 | "execution_count": null,
147 | "metadata": {
148 | "collapsed": false
149 | },
150 | "outputs": [],
151 | "source": [
152 | "df.loc['Albania':'Belgium', 'gdpPercap_1952':'gdpPercap_1962']"
153 | ]
154 | },
155 | {
156 | "cell_type": "markdown",
157 | "metadata": {},
158 | "source": [
159 | "How would you explain the difference between numerical and named slicing on DataFrames?"
160 | ]
161 | },
162 | {
163 | "cell_type": "markdown",
164 | "metadata": {},
165 | "source": [
166 | "_Integer slicing utilizes ..., and operates on the interval ..._\n",
167 | "\n",
168 | "_Whereas labeled utilizes ..., and operates on the interval ..._"
169 | ]
170 | },
171 | {
172 | "cell_type": "markdown",
173 | "metadata": {},
174 | "source": [
175 | "### Part 3"
176 | ]
177 | },
178 | {
179 | "cell_type": "markdown",
180 | "metadata": {},
181 | "source": [
182 | "Add comments to the steps below, describing what each does"
183 | ]
184 | },
185 | {
186 | "cell_type": "code",
187 | "execution_count": null,
188 | "metadata": {
189 | "collapsed": false
190 | },
191 | "outputs": [],
192 | "source": [
193 | "# first, ...\n",
194 | "first = pd.read_csv('data/gapminder_all.csv', index_col='country')\n",
195 | "# .head() is used to ...\n",
196 | "first.head()"
197 | ]
198 | },
199 | {
200 | "cell_type": "code",
201 | "execution_count": null,
202 | "metadata": {
203 | "collapsed": false
204 | },
205 | "outputs": [],
206 | "source": [
207 | "# second, ...\n",
208 | "second = first.loc[first['continent'] == 'Americas']\n",
209 | "second.head()"
210 | ]
211 | },
212 | {
213 | "cell_type": "code",
214 | "execution_count": null,
215 | "metadata": {
216 | "collapsed": false
217 | },
218 | "outputs": [],
219 | "source": [
220 | "# third, ...\n",
221 | "third = second.drop('Puerto Rico')\n",
222 | "print(second.shape, third.shape)"
223 | ]
224 | },
225 | {
226 | "cell_type": "code",
227 | "execution_count": null,
228 | "metadata": {
229 | "collapsed": false
230 | },
231 | "outputs": [],
232 | "source": [
233 | "# fourth, ...\n",
234 | "fourth = third.drop('continent', axis=1)\n",
235 | "fourth.head()"
236 | ]
237 | },
238 | {
239 | "cell_type": "code",
240 | "execution_count": null,
241 | "metadata": {
242 | "collapsed": true
243 | },
244 | "outputs": [],
245 | "source": [
246 | "# finally, ...\n",
247 | "fourth.to_csv('data/results.csv')"
248 | ]
249 | },
250 | {
251 | "cell_type": "markdown",
252 | "metadata": {},
253 | "source": [
254 | "### Part 4\n",
255 | "\n",
256 | "Go back to the European Gapminder data and answer the following questions:"
257 | ]
258 | },
259 | {
260 | "cell_type": "code",
261 | "execution_count": null,
262 | "metadata": {
263 | "collapsed": false
264 | },
265 | "outputs": [],
266 | "source": [
267 | "df = pd.read_csv('data/gapminder_gdp_europe.csv', index_col='country')\n",
268 | "df.head()"
269 | ]
270 | },
271 | {
272 | "cell_type": "markdown",
273 | "metadata": {},
274 | "source": [
275 | "**1**: List the GDP for each country in 1982 "
276 | ]
277 | },
278 | {
279 | "cell_type": "code",
280 | "execution_count": null,
281 | "metadata": {
282 | "collapsed": false
283 | },
284 | "outputs": [],
285 | "source": [
286 | "df"
287 | ]
288 | },
289 | {
290 | "cell_type": "markdown",
291 | "metadata": {},
292 | "source": [
293 | "**2**: What was the GDP per capita in Denmark for each year?"
294 | ]
295 | },
296 | {
297 | "cell_type": "code",
298 | "execution_count": null,
299 | "metadata": {
300 | "collapsed": false
301 | },
302 | "outputs": [],
303 | "source": [
304 | "df"
305 | ]
306 | },
307 | {
308 | "cell_type": "markdown",
309 | "metadata": {},
310 | "source": [
311 | "**4**: What was the GDP for the United Kingdom in each year _beginning in 1992_?"
312 | ]
313 | },
314 | {
315 | "cell_type": "code",
316 | "execution_count": null,
317 | "metadata": {
318 | "collapsed": false
319 | },
320 | "outputs": [],
321 | "source": [
322 | "df"
323 | ]
324 | },
325 | {
326 | "cell_type": "markdown",
327 | "metadata": {},
328 | "source": [
329 | "**5**: Calculate the ratio of each country's GDP per capita in 2007 to GDP per capita in 1952"
330 | ]
331 | },
332 | {
333 | "cell_type": "code",
334 | "execution_count": null,
335 | "metadata": {
336 | "collapsed": false
337 | },
338 | "outputs": [],
339 | "source": [
340 | "ratio = df\n",
341 | "ratio"
342 | ]
343 | },
344 | {
345 | "cell_type": "markdown",
346 | "metadata": {},
347 | "source": [
348 | "**6**: Which country had the largest relative GDP growth from 1952 to 2007?"
349 | ]
350 | },
351 | {
352 | "cell_type": "code",
353 | "execution_count": null,
354 | "metadata": {
355 | "collapsed": false
356 | },
357 | "outputs": [],
358 | "source": [
359 | "ratio"
360 | ]
361 | },
362 | {
363 | "cell_type": "markdown",
364 | "metadata": {},
365 | "source": [
366 | "**Bonus**: Can you think of another way to calculate #6?"
367 | ]
368 | },
369 | {
370 | "cell_type": "code",
371 | "execution_count": null,
372 | "metadata": {
373 | "collapsed": true
374 | },
375 | "outputs": [],
376 | "source": []
377 | },
378 | {
379 | "cell_type": "markdown",
380 | "metadata": {},
381 | "source": [
382 | "### Bonus Exercise\n",
383 | "\n",
384 | "Take a look at `data/gapminder_all.csv` again - can you figure out the median GDP per capita in 2007 within each continent?"
385 | ]
386 | },
387 | {
388 | "cell_type": "code",
389 | "execution_count": null,
390 | "metadata": {
391 | "collapsed": false
392 | },
393 | "outputs": [],
394 | "source": [
395 | "df = pd.read_csv()"
396 | ]
397 | },
398 | {
399 | "cell_type": "code",
400 | "execution_count": null,
401 | "metadata": {
402 | "collapsed": false
403 | },
404 | "outputs": [],
405 | "source": [
406 | "continental_gdp = df\n",
407 | "continental_gdp"
408 | ]
409 | }
410 | ],
411 | "metadata": {
412 | "anaconda-cloud": {},
413 | "kernelspec": {
414 | "display_name": "Python [conda root]",
415 | "language": "python",
416 | "name": "conda-root-py"
417 | },
418 | "language_info": {
419 | "codemirror_mode": {
420 | "name": "ipython",
421 | "version": 3
422 | },
423 | "file_extension": ".py",
424 | "mimetype": "text/x-python",
425 | "name": "python",
426 | "nbconvert_exporter": "python",
427 | "pygments_lexer": "ipython3",
428 | "version": "3.5.2"
429 | }
430 | },
431 | "nbformat": 4,
432 | "nbformat_minor": 1
433 | }
434 |
--------------------------------------------------------------------------------
/Lecture 3/data/asia_gdp_per_capita.csv:
--------------------------------------------------------------------------------
1 | 'year','Afghanistan','Bahrain','Bangladesh','Cambodia','China','Hong Kong China','India','Indonesia','Iran','Iraq','Israel','Japan','Jordan','Korea Dem. Rep.','Korea Rep.','Kuwait','Lebanon','Malaysia','Mongolia','Myanmar','Nepal','Oman','Pakistan','Philippines','Saudi Arabia','Singapore','Sri Lanka','Syria','Taiwan','Thailand','Vietnam','West Bank and Gaza','Yemen Rep.'
2 | 1952,779.4453145,9867.084765,684.2441716,368.4692856,400.4486107,3054.421209,546.5657493,749.6816546,3035.326002,4129.766056,4086.522128,3216.956347,1546.907807,1088.277758,1030.592226,108382.3529,4834.804067,1831.132894,786.5668575,331,545.8657229,1828.230307,684.5971438,1272.880995,6459.554823,2315.138227,1083.53203,1643.485354,1206.947913,757.7974177,605.0664917,1515.592329,781.7175761
3 | 1957,820.8530296,11635.79945,661.6374577,434.0383364,575.9870009,3629.076457,590.061996,858.9002707,3290.257643,6229.333562,5385.278451,4317.694365,1886.080591,1571.134655,1487.593537,113523.1329,6089.786934,1810.066992,912.6626085,350,597.9363558,2242.746551,747.0835292,1547.944844,8157.591248,2843.104409,1072.546602,2117.234893,1507.86129,793.5774148,676.2854478,1827.067742,804.8304547
4 | 1962,853.10071,12753.27514,686.3415538,496.9136476,487.6740183,4692.648272,658.3471509,849.2897701,4187.329802,8341.737815,7105.630706,6576.649461,2348.009158,1621.693598,1536.344387,95458.11176,5714.560611,2036.884944,1056.353958,388,652.3968593,2924.638113,803.3427418,1649.552153,11626.41975,3674.735572,1074.47196,2193.037133,1822.879028,1002.199172,772.0491602,2198.956312,825.6232006
5 | 1967,836.1971382,14804.6727,721.1860862,523.4323142,612.7056934,6197.962814,700.7706107,762.4317721,5906.731805,8931.459811,8393.741404,9847.788607,2741.796252,2143.540609,2029.228142,80894.88326,6006.983042,2277.742396,1226.04113,349,676.4422254,4720.942687,942.4082588,1814.12743,16903.04886,4977.41854,1135.514326,1881.923632,2643.858681,1295.46066,637.1232887,2649.715007,862.4421463
6 | 1972,739.9811058,18268.65839,630.2336265,421.6240257,676.9000921,8315.928145,724.032527,1111.107907,9613.818607,9576.037596,12786.93223,14778.78636,2110.856309,3701.621503,3030.87665,109347.867,7486.384341,2849.09478,1421.741975,357,674.7881296,10618.03855,1049.938981,1989.37407,24837.42865,8597.756202,1213.39553,2571.423014,4062.523897,1524.358936,699.5016441,3133.409277,1265.047031
7 | 1977,786.11336,19340.10196,659.8772322,524.9721832,741.2374699,11186.14125,813.337323,1382.702056,11888.59508,14688.23507,13306.61921,16610.37701,2852.351568,4106.301249,4657.22102,59265.47714,8659.696836,3827.921571,1647.511665,371,694.1124398,11848.34392,1175.921193,2373.204287,34167.7626,11210.08948,1348.775651,3195.484582,5596.519826,1961.224635,713.5371196,3682.831494,1829.765177
8 | 1982,978.0114388,19211.14731,676.9818656,624.4754784,962.4213805,14560.53051,855.7235377,1516.872988,7608.334602,14517.90711,15367.0292,19384.10571,4161.415959,4106.525293,5622.942464,31354.03573,7640.519521,4920.355951,2000.603139,424,718.3730947,12954.79101,1443.429832,2603.273765,33693.17525,15169.16112,1648.079789,3761.837715,7426.354774,2393.219781,707.2357863,4336.032082,1977.55701
9 | 1987,852.3959448,18524.02406,751.9794035,683.8955732,1378.904018,20038.47269,976.5126756,1748.356961,6642.881371,11643.57268,17122.47986,22375.94189,4448.679912,4106.492315,8533.088805,28118.42998,5377.091329,5249.802653,2338.008304,385,775.6324501,18115.22313,1704.686583,2189.634995,21198.26136,18861.53081,1876.766827,3116.774285,11054.56175,2982.653773,820.7994449,5107.197384,1971.741538
10 | 1992,649.3413952,19035.57917,837.8101643,682.3031755,1655.784158,24757.60301,1164.406809,2383.140898,7235.653188,3745.640687,18051.52254,26824.89511,3431.593647,3726.063507,12104.27872,34932.91959,6890.806854,7277.912802,1785.402016,347,897.7403604,18616.70691,1971.829464,2279.324017,24841.61777,24769.8912,2153.739222,3340.542768,15215.6579,4616.896545,989.0231487,6017.654756,1879.496673
11 | 1997,635.341351,20292.01679,972.7700352,734.28517,2289.234136,28377.63219,1458.817442,3119.335603,8263.590301,3076.239795,20896.60924,28816.58499,3645.379572,1690.756814,15993.52796,40300.61996,8754.96385,10132.90964,1902.2521,415,1010.892138,19702.05581,2049.350521,2536.534925,20586.69019,33519.4766,2664.477257,4014.238972,20206.82098,5852.625497,1385.896769,7110.667619,2117.484526
12 | 2002,726.7340548,23403.55927,1136.39043,896.2260153,3119.280896,30209.01516,1746.769454,2873.91287,9240.761975,4390.717312,21905.59514,28604.5919,3844.917194,1646.758151,19233.98818,35110.10566,9313.93883,10206.97794,2140.739323,611,1057.206311,19774.83687,2092.712441,2650.921068,19014.54118,36023.1054,3015.378833,4090.925331,23235.42329,5913.187529,1764.456677,4515.487575,2234.820827
13 | 2007,974.5803384,29796.04834,1391.253792,1713.778686,4959.114854,39724.97867,2452.210407,3540.651564,11605.71449,4471.061906,25523.2771,31656.06806,4519.461171,1593.06548,23348.13973,47306.98978,10461.05868,12451.6558,3095.772271,944,1091.359778,22316.19287,2605.94758,3190.481016,21654.83194,47143.17964,3970.095407,4184.548089,28718.27684,7458.396327,2441.576404,3025.349798,2280.769906
14 |
--------------------------------------------------------------------------------
/Lecture 3/data/baseball.csv:
--------------------------------------------------------------------------------
1 | id,player,year,stint,team,lg,g,ab,r,h,X2b,X3b,hr,rbi,sb,cs,bb,so,ibb,hbp,sh,sf,gidp
2 | 88641,womacto01,2006,2,CHN,NL,19,50,6,14,1,0,1,2.0,1.0,1.0,4,4.0,0.0,0.0,3.0,0.0,0.0
3 | 88643,schilcu01,2006,1,BOS,AL,31,2,0,1,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
4 | 88645,myersmi01,2006,1,NYA,AL,62,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
5 | 88649,helliri01,2006,1,MIL,NL,20,3,0,0,0,0,0,0.0,0.0,0.0,0,2.0,0.0,0.0,0.0,0.0,0.0
6 | 88650,johnsra05,2006,1,NYA,AL,33,6,0,1,0,0,0,0.0,0.0,0.0,0,4.0,0.0,0.0,0.0,0.0,0.0
7 | 88652,finlest01,2006,1,SFN,NL,139,426,66,105,21,12,6,40.0,7.0,0.0,46,55.0,2.0,2.0,3.0,4.0,6.0
8 | 88653,gonzalu01,2006,1,ARI,NL,153,586,93,159,52,2,15,73.0,0.0,1.0,69,58.0,10.0,7.0,0.0,6.0,14.0
9 | 88662,seleaa01,2006,1,LAN,NL,28,26,2,5,1,0,0,0.0,0.0,0.0,1,7.0,0.0,0.0,6.0,0.0,1.0
10 | 89177,francju01,2007,2,ATL,NL,15,40,1,10,3,0,0,8.0,0.0,0.0,4,10.0,1.0,0.0,0.0,1.0,1.0
11 | 89178,francju01,2007,1,NYN,NL,40,50,7,10,0,0,1,8.0,2.0,1.0,10,13.0,0.0,0.0,0.0,1.0,1.0
12 | 89330,zaungr01,2007,1,TOR,AL,110,331,43,80,24,1,10,52.0,0.0,0.0,51,55.0,8.0,2.0,1.0,6.0,9.0
13 | 89333,witasja01,2007,1,TBA,AL,3,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
14 | 89334,williwo02,2007,1,HOU,NL,33,59,3,6,0,0,1,2.0,0.0,0.0,0,25.0,0.0,0.0,5.0,0.0,1.0
15 | 89335,wickmbo01,2007,2,ARI,NL,8,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
16 | 89336,wickmbo01,2007,1,ATL,NL,47,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
17 | 89337,whitero02,2007,1,MIN,AL,38,109,8,19,4,0,4,20.0,0.0,0.0,6,19.0,0.0,3.0,0.0,1.0,2.0
18 | 89338,whiteri01,2007,1,HOU,NL,20,1,0,0,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
19 | 89339,wellsda01,2007,2,LAN,NL,7,15,2,4,1,0,0,1.0,0.0,0.0,0,6.0,0.0,0.0,0.0,0.0,0.0
20 | 89340,wellsda01,2007,1,SDN,NL,22,38,1,4,0,0,0,0.0,0.0,0.0,0,12.0,0.0,0.0,4.0,0.0,0.0
21 | 89341,weathda01,2007,1,CIN,NL,67,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
22 | 89343,walketo04,2007,1,OAK,AL,18,48,5,13,1,0,0,4.0,0.0,0.0,2,4.0,0.0,0.0,0.0,2.0,2.0
23 | 89345,wakefti01,2007,1,BOS,AL,1,2,0,0,0,0,0,0.0,0.0,0.0,0,2.0,0.0,0.0,0.0,0.0,0.0
24 | 89347,vizquom01,2007,1,SFN,NL,145,513,54,126,18,3,4,51.0,14.0,6.0,44,48.0,6.0,1.0,14.0,3.0,14.0
25 | 89348,villoro01,2007,1,NYA,AL,6,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
26 | 89352,valenjo03,2007,1,NYN,NL,51,166,18,40,11,1,3,18.0,2.0,1.0,15,28.0,4.0,0.0,1.0,1.0,5.0
27 | 89354,trachst01,2007,2,CHN,NL,4,7,0,1,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
28 | 89355,trachst01,2007,1,BAL,AL,3,5,0,0,0,0,0,0.0,0.0,0.0,0,3.0,0.0,0.0,0.0,0.0,0.0
29 | 89359,timlimi01,2007,1,BOS,AL,4,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
30 | 89360,thomeji01,2007,1,CHA,AL,130,432,79,119,19,0,35,96.0,0.0,1.0,95,134.0,11.0,6.0,0.0,3.0,10.0
31 | 89361,thomafr04,2007,1,TOR,AL,155,531,63,147,30,0,26,95.0,0.0,0.0,81,94.0,3.0,7.0,0.0,5.0,14.0
32 | 89363,tavarju01,2007,1,BOS,AL,2,4,0,1,0,0,0,0.0,0.0,0.0,1,3.0,0.0,0.0,0.0,0.0,0.0
33 | 89365,sweenma01,2007,2,LAN,NL,30,33,2,9,1,0,0,3.0,0.0,0.0,1,11.0,0.0,0.0,0.0,0.0,0.0
34 | 89366,sweenma01,2007,1,SFN,NL,76,90,18,23,8,0,2,10.0,2.0,0.0,13,18.0,0.0,3.0,1.0,0.0,0.0
35 | 89367,suppaje01,2007,1,MIL,NL,33,61,4,8,0,0,0,2.0,0.0,0.0,3,16.0,0.0,0.0,11.0,0.0,2.0
36 | 89368,stinnke01,2007,1,SLN,NL,26,82,7,13,3,0,1,5.0,0.0,0.0,5,22.0,2.0,0.0,0.0,0.0,2.0
37 | 89370,stantmi02,2007,1,CIN,NL,67,2,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
38 | 89371,stairma01,2007,1,TOR,AL,125,357,58,103,28,1,21,64.0,2.0,1.0,44,66.0,5.0,2.0,0.0,2.0,7.0
39 | 89372,sprinru01,2007,1,SLN,NL,72,1,0,0,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
40 | 89374,sosasa01,2007,1,TEX,AL,114,412,53,104,24,1,21,92.0,0.0,0.0,34,112.0,3.0,3.0,0.0,5.0,11.0
41 | 89375,smoltjo01,2007,1,ATL,NL,30,54,1,5,1,0,0,2.0,0.0,0.0,1,19.0,0.0,0.0,13.0,0.0,0.0
42 | 89378,sheffga01,2007,1,DET,AL,133,494,107,131,20,1,25,75.0,22.0,5.0,84,71.0,2.0,9.0,0.0,6.0,10.0
43 | 89381,seleaa01,2007,1,NYN,NL,31,4,0,0,0,0,0,0.0,0.0,0.0,1,1.0,0.0,0.0,1.0,0.0,0.0
44 | 89382,seaneru01,2007,1,LAN,NL,68,1,0,0,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
45 | 89383,schmija01,2007,1,LAN,NL,6,7,1,1,0,0,1,1.0,0.0,0.0,0,4.0,0.0,0.0,1.0,0.0,0.0
46 | 89384,schilcu01,2007,1,BOS,AL,1,2,0,1,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
47 | 89385,sandere02,2007,1,KCA,AL,24,73,12,23,7,0,2,11.0,0.0,1.0,11,15.0,0.0,1.0,0.0,0.0,2.0
48 | 89388,rogerke01,2007,1,DET,AL,1,2,0,0,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
49 | 89389,rodriiv01,2007,1,DET,AL,129,502,50,141,31,3,11,63.0,2.0,2.0,9,96.0,1.0,1.0,1.0,2.0,16.0
50 | 89396,ramirma02,2007,1,BOS,AL,133,483,84,143,33,1,20,88.0,0.0,0.0,71,92.0,13.0,7.0,0.0,8.0,21.0
51 | 89398,piazzmi01,2007,1,OAK,AL,83,309,33,85,17,1,8,44.0,0.0,0.0,18,61.0,0.0,0.0,0.0,2.0,9.0
52 | 89400,perezne01,2007,1,DET,AL,33,64,5,11,3,0,1,6.0,0.0,0.0,4,8.0,0.0,0.0,3.0,0.0,2.0
53 | 89402,parkch01,2007,1,NYN,NL,1,1,0,0,0,0,0,0.0,0.0,0.0,0,1.0,0.0,0.0,0.0,0.0,0.0
54 | 89406,oliveda02,2007,1,LAA,AL,5,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
55 | 89410,myersmi01,2007,1,NYA,AL,6,1,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
56 | 89411,mussimi01,2007,1,NYA,AL,2,2,0,0,0,0,0,0.0,0.0,0.0,1,0.0,0.0,0.0,0.0,0.0,0.0
57 | 89412,moyerja01,2007,1,PHI,NL,33,73,4,9,2,0,0,2.0,0.0,0.0,2,26.0,0.0,0.0,8.0,0.0,1.0
58 | 89420,mesajo01,2007,1,PHI,NL,38,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
59 | 89421,martipe02,2007,1,NYN,NL,5,9,1,1,1,0,0,0.0,0.0,0.0,0,6.0,0.0,0.0,2.0,0.0,0.0
60 | 89425,maddugr01,2007,1,SDN,NL,33,62,2,9,2,0,0,0.0,1.0,0.0,1,19.0,0.0,0.0,9.0,0.0,2.0
61 | 89426,mabryjo01,2007,1,COL,NL,28,34,4,4,1,0,1,5.0,0.0,0.0,5,10.0,0.0,0.0,0.0,0.0,1.0
62 | 89429,loftoke01,2007,2,CLE,AL,52,173,24,49,9,3,0,15.0,2.0,3.0,17,23.0,0.0,0.0,4.0,2.0,1.0
63 | 89430,loftoke01,2007,1,TEX,AL,84,317,62,96,16,3,7,23.0,21.0,4.0,39,28.0,1.0,2.0,2.0,3.0,5.0
64 | 89431,loaizes01,2007,1,LAN,NL,5,7,0,1,0,0,0,2.0,0.0,0.0,0,2.0,0.0,0.0,2.0,0.0,1.0
65 | 89438,kleskry01,2007,1,SFN,NL,116,362,51,94,27,3,6,44.0,5.0,1.0,46,68.0,2.0,1.0,1.0,1.0,14.0
66 | 89439,kentje01,2007,1,LAN,NL,136,494,78,149,36,1,20,79.0,1.0,3.0,57,61.0,4.0,5.0,0.0,6.0,17.0
67 | 89442,jonesto02,2007,1,DET,AL,5,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
68 | 89445,johnsra05,2007,1,ARI,NL,10,15,0,1,0,0,0,0.0,0.0,0.0,1,7.0,0.0,0.0,2.0,0.0,0.0
69 | 89450,hoffmtr01,2007,1,SDN,NL,60,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
70 | 89451,hernaro01,2007,2,LAN,NL,22,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
71 | 89452,hernaro01,2007,1,CLE,AL,2,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
72 | 89460,guarded01,2007,1,CIN,NL,15,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
73 | 89462,griffke02,2007,1,CIN,NL,144,528,78,146,24,1,30,93.0,6.0,1.0,85,99.0,14.0,1.0,0.0,9.0,14.0
74 | 89463,greensh01,2007,1,NYN,NL,130,446,62,130,30,1,10,46.0,11.0,1.0,37,62.0,4.0,5.0,1.0,1.0,14.0
75 | 89464,graffto01,2007,1,MIL,NL,86,231,34,55,8,0,9,30.0,0.0,1.0,24,44.0,6.0,3.0,0.0,2.0,7.0
76 | 89465,gordoto01,2007,1,PHI,NL,44,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
77 | 89466,gonzalu01,2007,1,LAN,NL,139,464,70,129,23,2,15,68.0,6.0,2.0,56,56.0,4.0,4.0,0.0,2.0,11.0
78 | 89467,gomezch02,2007,2,CLE,AL,19,53,4,15,2,0,0,5.0,0.0,0.0,0,6.0,0.0,0.0,1.0,1.0,1.0
79 | 89468,gomezch02,2007,1,BAL,AL,73,169,17,51,10,1,1,16.0,1.0,2.0,10,20.0,1.0,0.0,5.0,1.0,5.0
80 | 89469,glavito02,2007,1,NYN,NL,33,56,3,12,1,0,0,4.0,0.0,0.0,6,5.0,0.0,0.0,12.0,1.0,0.0
81 | 89473,floydcl01,2007,1,CHN,NL,108,282,40,80,10,1,9,45.0,0.0,0.0,35,47.0,5.0,5.0,0.0,0.0,6.0
82 | 89474,finlest01,2007,1,COL,NL,43,94,9,17,3,0,1,2.0,0.0,0.0,8,4.0,1.0,0.0,0.0,0.0,2.0
83 | 89480,embreal01,2007,1,OAK,AL,4,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
84 | 89481,edmonji01,2007,1,SLN,NL,117,365,39,92,15,2,12,53.0,0.0,2.0,41,75.0,2.0,0.0,2.0,3.0,9.0
85 | 89482,easleda01,2007,1,NYN,NL,76,193,24,54,6,0,10,26.0,0.0,1.0,19,35.0,1.0,5.0,0.0,1.0,2.0
86 | 89489,delgaca01,2007,1,NYN,NL,139,538,71,139,30,0,24,87.0,4.0,0.0,52,118.0,8.0,11.0,0.0,6.0,12.0
87 | 89493,cormirh01,2007,1,CIN,NL,6,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
88 | 89494,coninje01,2007,2,NYN,NL,21,41,2,8,2,0,0,5.0,0.0,0.0,7,8.0,2.0,0.0,1.0,1.0,1.0
89 | 89495,coninje01,2007,1,CIN,NL,80,215,23,57,11,1,6,32.0,4.0,0.0,20,28.0,0.0,0.0,1.0,6.0,4.0
90 | 89497,clemero02,2007,1,NYA,AL,2,2,0,1,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
91 | 89498,claytro01,2007,2,BOS,AL,8,6,1,0,0,0,0,0.0,0.0,0.0,0,3.0,0.0,0.0,0.0,0.0,2.0
92 | 89499,claytro01,2007,1,TOR,AL,69,189,23,48,14,0,1,12.0,2.0,1.0,14,50.0,0.0,1.0,3.0,3.0,8.0
93 | 89501,cirilje01,2007,2,ARI,NL,28,40,6,8,4,0,0,6.0,0.0,0.0,4,6.0,0.0,0.0,0.0,0.0,1.0
94 | 89502,cirilje01,2007,1,MIN,AL,50,153,18,40,9,2,2,21.0,2.0,0.0,15,13.0,0.0,1.0,3.0,2.0,9.0
95 | 89521,bondsba01,2007,1,SFN,NL,126,340,75,94,14,0,28,66.0,5.0,0.0,132,54.0,43.0,3.0,0.0,2.0,13.0
96 | 89523,biggicr01,2007,1,HOU,NL,141,517,68,130,31,3,10,50.0,4.0,3.0,23,112.0,0.0,3.0,7.0,5.0,5.0
97 | 89525,benitar01,2007,2,FLO,NL,34,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
98 | 89526,benitar01,2007,1,SFN,NL,19,0,0,0,0,0,0,0.0,0.0,0.0,0,0.0,0.0,0.0,0.0,0.0,0.0
99 | 89530,ausmubr01,2007,1,HOU,NL,117,349,38,82,16,3,3,25.0,6.0,1.0,37,74.0,3.0,6.0,4.0,1.0,11.0
100 | 89533,aloumo01,2007,1,NYN,NL,87,328,51,112,19,1,13,49.0,3.0,0.0,27,30.0,5.0,2.0,0.0,3.0,13.0
101 | 89534,alomasa02,2007,1,NYN,NL,8,22,1,3,1,0,0,0.0,0.0,0.0,0,3.0,0.0,0.0,0.0,0.0,0.0
102 |
--------------------------------------------------------------------------------
/Lecture 3/data/gapminder_gdp_africa.csv:
--------------------------------------------------------------------------------
1 | country,gdpPercap_1952,gdpPercap_1957,gdpPercap_1962,gdpPercap_1967,gdpPercap_1972,gdpPercap_1977,gdpPercap_1982,gdpPercap_1987,gdpPercap_1992,gdpPercap_1997,gdpPercap_2002,gdpPercap_2007
2 | Algeria,2449.008185,3013.976023,2550.81688,3246.991771,4182.663766,4910.416756,5745.160213,5681.358539,5023.216647,4797.295051,5288.040382,6223.367465
3 | Angola,3520.610273,3827.940465,4269.276742,5522.776375,5473.288005,3008.647355,2756.953672,2430.208311,2627.845685,2277.140884,2773.287312,4797.231267
4 | Benin,1062.7522,959.6010805,949.4990641,1035.831411,1085.796879,1029.161251,1277.897616,1225.85601,1191.207681,1232.975292,1372.877931,1441.284873
5 | Botswana,851.2411407,918.2325349,983.6539764,1214.709294,2263.611114,3214.857818,4551.14215,6205.88385,7954.111645,8647.142313,11003.60508,12569.85177
6 | Burkina Faso,543.2552413,617.1834648,722.5120206,794.8265597,854.7359763,743.3870368,807.1985855,912.0631417,931.7527731,946.2949618,1037.645221,1217.032994
7 | Burundi,339.2964587,379.5646281,355.2032273,412.9775136,464.0995039,556.1032651,559.603231,621.8188189,631.6998778,463.1151478,446.4035126,430.0706916
8 | Cameroon,1172.667655,1313.048099,1399.607441,1508.453148,1684.146528,1783.432873,2367.983282,2602.664206,1793.163278,1694.337469,1934.011449,2042.09524
9 | Central African Republic,1071.310713,1190.844328,1193.068753,1136.056615,1070.013275,1109.374338,956.7529907,844.8763504,747.9055252,740.5063317,738.6906068,706.016537
10 | Chad,1178.665927,1308.495577,1389.817618,1196.810565,1104.103987,1133.98495,797.9081006,952.386129,1058.0643,1004.961353,1156.18186,1704.063724
11 | Comoros,1102.990936,1211.148548,1406.648278,1876.029643,1937.577675,1172.603047,1267.100083,1315.980812,1246.90737,1173.618235,1075.811558,986.1478792
12 | Congo Dem. Rep.,780.5423257,905.8602303,896.3146335,861.5932424,904.8960685,795.757282,673.7478181,672.774812,457.7191807,312.188423,241.1658765,277.5518587
13 | Congo Rep.,2125.621418,2315.056572,2464.783157,2677.939642,3213.152683,3259.178978,4879.507522,4201.194937,4016.239529,3484.164376,3484.06197,3632.557798
14 | Cote d'Ivoire,1388.594732,1500.895925,1728.869428,2052.050473,2378.201111,2517.736547,2602.710169,2156.956069,1648.073791,1786.265407,1648.800823,1544.750112
15 | Djibouti,2669.529475,2864.969076,3020.989263,3020.050513,3694.212352,3081.761022,2879.468067,2880.102568,2377.156192,1895.016984,1908.260867,2082.481567
16 | Egypt,1418.822445,1458.915272,1693.335853,1814.880728,2024.008147,2785.493582,3503.729636,3885.46071,3794.755195,4173.181797,4754.604414,5581.180998
17 | Equatorial Guinea,375.6431231,426.0964081,582.8419714,915.5960025,672.4122571,958.5668124,927.8253427,966.8968149,1132.055034,2814.480755,7703.4959,12154.08975
18 | Eritrea,328.9405571,344.1618859,380.9958433,468.7949699,514.3242082,505.7538077,524.8758493,521.1341333,582.8585102,913.47079,765.3500015,641.3695236
19 | Ethiopia,362.1462796,378.9041632,419.4564161,516.1186438,566.2439442,556.8083834,577.8607471,573.7413142,421.3534653,515.8894013,530.0535319,690.8055759
20 | Gabon,4293.476475,4976.198099,6631.459222,8358.761987,11401.94841,21745.57328,15113.36194,11864.40844,13522.15752,14722.84188,12521.71392,13206.48452
21 | Gambia,485.2306591,520.9267111,599.650276,734.7829124,756.0868363,884.7552507,835.8096108,611.6588611,665.6244126,653.7301704,660.5855997,752.7497265
22 | Ghana,911.2989371,1043.561537,1190.041118,1125.69716,1178.223708,993.2239571,876.032569,847.0061135,925.060154,1005.245812,1111.984578,1327.60891
23 | Guinea,510.1964923,576.2670245,686.3736739,708.7595409,741.6662307,874.6858643,857.2503577,805.5724718,794.3484384,869.4497668,945.5835837,942.6542111
24 | Guinea-Bissau,299.850319,431.7904566,522.0343725,715.5806402,820.2245876,764.7259628,838.1239671,736.4153921,745.5398706,796.6644681,575.7047176,579.231743
25 | Kenya,853.540919,944.4383152,896.9663732,1056.736457,1222.359968,1267.613204,1348.225791,1361.936856,1341.921721,1360.485021,1287.514732,1463.249282
26 | Lesotho,298.8462121,335.9971151,411.8006266,498.6390265,496.5815922,745.3695408,797.2631074,773.9932141,977.4862725,1186.147994,1275.184575,1569.331442
27 | Liberia,575.5729961,620.9699901,634.1951625,713.6036483,803.0054535,640.3224383,572.1995694,506.1138573,636.6229191,609.1739508,531.4823679,414.5073415
28 | Libya,2387.54806,3448.284395,6757.030816,18772.75169,21011.49721,21951.21176,17364.27538,11770.5898,9640.138501,9467.446056,9534.677467,12057.49928
29 | Madagascar,1443.011715,1589.20275,1643.38711,1634.047282,1748.562982,1544.228586,1302.878658,1155.441948,1040.67619,986.2958956,894.6370822,1044.770126
30 | Malawi,369.1650802,416.3698064,427.9010856,495.5147806,584.6219709,663.2236766,632.8039209,635.5173634,563.2000145,692.2758103,665.4231186,759.3499101
31 | Mali,452.3369807,490.3821867,496.1743428,545.0098873,581.3688761,686.3952693,618.0140641,684.1715576,739.014375,790.2579846,951.4097518,1042.581557
32 | Mauritania,743.1159097,846.1202613,1055.896036,1421.145193,1586.851781,1497.492223,1481.150189,1421.603576,1361.369784,1483.136136,1579.019543,1803.151496
33 | Mauritius,1967.955707,2034.037981,2529.067487,2475.387562,2575.484158,3710.982963,3688.037739,4783.586903,6058.253846,7425.705295,9021.815894,10956.99112
34 | Morocco,1688.20357,1642.002314,1566.353493,1711.04477,1930.194975,2370.619976,2702.620356,2755.046991,2948.047252,2982.101858,3258.495584,3820.17523
35 | Mozambique,468.5260381,495.5868333,556.6863539,566.6691539,724.9178037,502.3197334,462.2114149,389.8761846,410.8968239,472.3460771,633.6179466,823.6856205
36 | Namibia,2423.780443,2621.448058,3173.215595,3793.694753,3746.080948,3876.485958,4191.100511,3693.731337,3804.537999,3899.52426,4072.324751,4811.060429
37 | Niger,761.879376,835.5234025,997.7661127,1054.384891,954.2092363,808.8970728,909.7221354,668.3000228,581.182725,580.3052092,601.0745012,619.6768924
38 | Nigeria,1077.281856,1100.592563,1150.927478,1014.514104,1698.388838,1981.951806,1576.97375,1385.029563,1619.848217,1624.941275,1615.286395,2013.977305
39 | Reunion,2718.885295,2769.451844,3173.72334,4021.175739,5047.658563,4319.804067,5267.219353,5303.377488,6101.255823,6071.941411,6316.1652,7670.122558
40 | Rwanda,493.3238752,540.2893983,597.4730727,510.9637142,590.5806638,670.0806011,881.5706467,847.991217,737.0685949,589.9445051,785.6537648,863.0884639
41 | Sao Tome and Principe,879.5835855,860.7369026,1071.551119,1384.840593,1532.985254,1737.561657,1890.218117,1516.525457,1428.777814,1339.076036,1353.09239,1598.435089
42 | Senegal,1450.356983,1567.653006,1654.988723,1612.404632,1597.712056,1561.769116,1518.479984,1441.72072,1367.899369,1392.368347,1519.635262,1712.472136
43 | Sierra Leone,879.7877358,1004.484437,1116.639877,1206.043465,1353.759762,1348.285159,1465.010784,1294.447788,1068.696278,574.6481576,699.489713,862.5407561
44 | Somalia,1135.749842,1258.147413,1369.488336,1284.73318,1254.576127,1450.992513,1176.807031,1093.244963,926.9602964,930.5964284,882.0818218,926.1410683
45 | South Africa,4725.295531,5487.104219,5768.729717,7114.477971,7765.962636,8028.651439,8568.266228,7825.823398,7225.069258,7479.188244,7710.946444,9269.657808
46 | Sudan,1615.991129,1770.337074,1959.593767,1687.997641,1659.652775,2202.988423,1895.544073,1507.819159,1492.197043,1632.210764,1993.398314,2602.394995
47 | Swaziland,1148.376626,1244.708364,1856.182125,2613.101665,3364.836625,3781.410618,3895.384018,3984.839812,3553.0224,3876.76846,4128.116943,4513.480643
48 | Tanzania,716.6500721,698.5356073,722.0038073,848.2186575,915.9850592,962.4922932,874.2426069,831.8220794,825.682454,789.1862231,899.0742111,1107.482182
49 | Togo,859.8086567,925.9083202,1067.53481,1477.59676,1649.660188,1532.776998,1344.577953,1202.201361,1034.298904,982.2869243,886.2205765,882.9699438
50 | Tunisia,1468.475631,1395.232468,1660.30321,1932.360167,2753.285994,3120.876811,3560.233174,3810.419296,4332.720164,4876.798614,5722.895655,7092.923025
51 | Uganda,734.753484,774.3710692,767.2717398,908.9185217,950.735869,843.7331372,682.2662268,617.7244065,644.1707969,816.559081,927.7210018,1056.380121
52 | Zambia,1147.388831,1311.956766,1452.725766,1777.077318,1773.498265,1588.688299,1408.678565,1213.315116,1210.884633,1071.353818,1071.613938,1271.211593
53 | Zimbabwe,406.8841148,518.7642681,527.2721818,569.7950712,799.3621758,685.5876821,788.8550411,706.1573059,693.4207856,792.4499603,672.0386227,469.7092981
54 |
--------------------------------------------------------------------------------
/Lecture 3/data/gapminder_gdp_americas.csv:
--------------------------------------------------------------------------------
1 | continent,country,gdpPercap_1952,gdpPercap_1957,gdpPercap_1962,gdpPercap_1967,gdpPercap_1972,gdpPercap_1977,gdpPercap_1982,gdpPercap_1987,gdpPercap_1992,gdpPercap_1997,gdpPercap_2002,gdpPercap_2007
2 | Americas,Argentina,5911.315053,6856.856212,7133.166023,8052.953021,9443.038526,10079.02674,8997.897412,9139.671389,9308.41871,10967.28195,8797.640716,12779.37964
3 | Americas,Bolivia,2677.326347,2127.686326,2180.972546,2586.886053,2980.331339,3548.097832,3156.510452,2753.69149,2961.699694,3326.143191,3413.26269,3822.137084
4 | Americas,Brazil,2108.944355,2487.365989,3336.585802,3429.864357,4985.711467,6660.118654,7030.835878,7807.095818,6950.283021,7957.980824,8131.212843,9065.800825
5 | Americas,Canada,11367.16112,12489.95006,13462.48555,16076.58803,18970.57086,22090.88306,22898.79214,26626.51503,26342.88426,28954.92589,33328.96507,36319.23501
6 | Americas,Chile,3939.978789,4315.622723,4519.094331,5106.654313,5494.024437,4756.763836,5095.665738,5547.063754,7596.125964,10118.05318,10778.78385,13171.63885
7 | Americas,Colombia,2144.115096,2323.805581,2492.351109,2678.729839,3264.660041,3815.80787,4397.575659,4903.2191,5444.648617,6117.361746,5755.259962,7006.580419
8 | Americas,Costa Rica,2627.009471,2990.010802,3460.937025,4161.727834,5118.146939,5926.876967,5262.734751,5629.915318,6160.416317,6677.045314,7723.447195,9645.06142
9 | Americas,Cuba,5586.53878,6092.174359,5180.75591,5690.268015,5305.445256,6380.494966,7316.918107,7532.924763,5592.843963,5431.990415,6340.646683,8948.102923
10 | Americas,Dominican Republic,1397.717137,1544.402995,1662.137359,1653.723003,2189.874499,2681.9889,2861.092386,2899.842175,3044.214214,3614.101285,4563.808154,6025.374752
11 | Americas,Ecuador,3522.110717,3780.546651,4086.114078,4579.074215,5280.99471,6679.62326,7213.791267,6481.776993,7103.702595,7429.455877,5773.044512,6873.262326
12 | Americas,El Salvador,3048.3029,3421.523218,3776.803627,4358.595393,4520.246008,5138.922374,4098.344175,4140.442097,4444.2317,5154.825496,5351.568666,5728.353514
13 | Americas,Guatemala,2428.237769,2617.155967,2750.364446,3242.531147,4031.408271,4879.992748,4820.49479,4246.485974,4439.45084,4684.313807,4858.347495,5186.050003
14 | Americas,Haiti,1840.366939,1726.887882,1796.589032,1452.057666,1654.456946,1874.298931,2011.159549,1823.015995,1456.309517,1341.726931,1270.364932,1201.637154
15 | Americas,Honduras,2194.926204,2220.487682,2291.156835,2538.269358,2529.842345,3203.208066,3121.760794,3023.096699,3081.694603,3160.454906,3099.72866,3548.330846
16 | Americas,Jamaica,2898.530881,4756.525781,5246.107524,6124.703451,7433.889293,6650.195573,6068.05135,6351.237495,7404.923685,7121.924704,6994.774861,7320.880262
17 | Americas,Mexico,3478.125529,4131.546641,4581.609385,5754.733883,6809.40669,7674.929108,9611.147541,8688.156003,9472.384295,9767.29753,10742.44053,11977.57496
18 | Americas,Nicaragua,3112.363948,3457.415947,3634.364406,4643.393534,4688.593267,5486.371089,3470.338156,2955.984375,2170.151724,2253.023004,2474.548819,2749.320965
19 | Americas,Panama,2480.380334,2961.800905,3536.540301,4421.009084,5364.249663,5351.912144,7009.601598,7034.779161,6618.74305,7113.692252,7356.031934,9809.185636
20 | Americas,Paraguay,1952.308701,2046.154706,2148.027146,2299.376311,2523.337977,3248.373311,4258.503604,3998.875695,4196.411078,4247.400261,3783.674243,4172.838464
21 | Americas,Peru,3758.523437,4245.256698,4957.037982,5788.09333,5937.827283,6281.290855,6434.501797,6360.943444,4446.380924,5838.347657,5909.020073,7408.905561
22 | Americas,Puerto Rico,3081.959785,3907.156189,5108.34463,6929.277714,9123.041742,9770.524921,10330.98915,12281.34191,14641.58711,16999.4333,18855.60618,19328.70901
23 | Americas,Trinidad and Tobago,3023.271928,4100.3934,4997.523971,5621.368472,6619.551419,7899.554209,9119.528607,7388.597823,7370.990932,8792.573126,11460.60023,18008.50924
24 | Americas,United States,13990.48208,14847.12712,16173.14586,19530.36557,21806.03594,24072.63213,25009.55914,29884.35041,32003.93224,35767.43303,39097.09955,42951.65309
25 | Americas,Uruguay,5716.766744,6150.772969,5603.357717,5444.61962,5703.408898,6504.339663,6920.223051,7452.398969,8137.004775,9230.240708,7727.002004,10611.46299
26 | Americas,Venezuela,7689.799761,9802.466526,8422.974165,9541.474188,10505.25966,13143.95095,11152.41011,9883.584648,10733.92631,10165.49518,8605.047831,11415.80569
27 |
--------------------------------------------------------------------------------
/Lecture 3/data/gapminder_gdp_asia.csv:
--------------------------------------------------------------------------------
1 | country,gdpPercap_1952,gdpPercap_1957,gdpPercap_1962,gdpPercap_1967,gdpPercap_1972,gdpPercap_1977,gdpPercap_1982,gdpPercap_1987,gdpPercap_1992,gdpPercap_1997,gdpPercap_2002,gdpPercap_2007
2 | Afghanistan,779.4453145,820.8530296,853.10071,836.1971382,739.9811058,786.11336,978.0114388,852.3959448,649.3413952,635.341351,726.7340548,974.5803384
3 | Bahrain,9867.084765,11635.79945,12753.27514,14804.6727,18268.65839,19340.10196,19211.14731,18524.02406,19035.57917,20292.01679,23403.55927,29796.04834
4 | Bangladesh,684.2441716,661.6374577,686.3415538,721.1860862,630.2336265,659.8772322,676.9818656,751.9794035,837.8101643,972.7700352,1136.39043,1391.253792
5 | Cambodia,368.4692856,434.0383364,496.9136476,523.4323142,421.6240257,524.9721832,624.4754784,683.8955732,682.3031755,734.28517,896.2260153,1713.778686
6 | China,400.4486107,575.9870009,487.6740183,612.7056934,676.9000921,741.2374699,962.4213805,1378.904018,1655.784158,2289.234136,3119.280896,4959.114854
7 | Hong Kong China,3054.421209,3629.076457,4692.648272,6197.962814,8315.928145,11186.14125,14560.53051,20038.47269,24757.60301,28377.63219,30209.01516,39724.97867
8 | India,546.5657493,590.061996,658.3471509,700.7706107,724.032527,813.337323,855.7235377,976.5126756,1164.406809,1458.817442,1746.769454,2452.210407
9 | Indonesia,749.6816546,858.9002707,849.2897701,762.4317721,1111.107907,1382.702056,1516.872988,1748.356961,2383.140898,3119.335603,2873.91287,3540.651564
10 | Iran,3035.326002,3290.257643,4187.329802,5906.731805,9613.818607,11888.59508,7608.334602,6642.881371,7235.653188,8263.590301,9240.761975,11605.71449
11 | Iraq,4129.766056,6229.333562,8341.737815,8931.459811,9576.037596,14688.23507,14517.90711,11643.57268,3745.640687,3076.239795,4390.717312,4471.061906
12 | Israel,4086.522128,5385.278451,7105.630706,8393.741404,12786.93223,13306.61921,15367.0292,17122.47986,18051.52254,20896.60924,21905.59514,25523.2771
13 | Japan,3216.956347,4317.694365,6576.649461,9847.788607,14778.78636,16610.37701,19384.10571,22375.94189,26824.89511,28816.58499,28604.5919,31656.06806
14 | Jordan,1546.907807,1886.080591,2348.009158,2741.796252,2110.856309,2852.351568,4161.415959,4448.679912,3431.593647,3645.379572,3844.917194,4519.461171
15 | Korea Dem. Rep.,1088.277758,1571.134655,1621.693598,2143.540609,3701.621503,4106.301249,4106.525293,4106.492315,3726.063507,1690.756814,1646.758151,1593.06548
16 | Korea Rep.,1030.592226,1487.593537,1536.344387,2029.228142,3030.87665,4657.22102,5622.942464,8533.088805,12104.27872,15993.52796,19233.98818,23348.13973
17 | Kuwait,108382.3529,113523.1329,95458.11176,80894.88326,109347.867,59265.47714,31354.03573,28118.42998,34932.91959,40300.61996,35110.10566,47306.98978
18 | Lebanon,4834.804067,6089.786934,5714.560611,6006.983042,7486.384341,8659.696836,7640.519521,5377.091329,6890.806854,8754.96385,9313.93883,10461.05868
19 | Malaysia,1831.132894,1810.066992,2036.884944,2277.742396,2849.09478,3827.921571,4920.355951,5249.802653,7277.912802,10132.90964,10206.97794,12451.6558
20 | Mongolia,786.5668575,912.6626085,1056.353958,1226.04113,1421.741975,1647.511665,2000.603139,2338.008304,1785.402016,1902.2521,2140.739323,3095.772271
21 | Myanmar,331,350,388,349,357,371,424,385,347,415,611,944
22 | Nepal,545.8657229,597.9363558,652.3968593,676.4422254,674.7881296,694.1124398,718.3730947,775.6324501,897.7403604,1010.892138,1057.206311,1091.359778
23 | Oman,1828.230307,2242.746551,2924.638113,4720.942687,10618.03855,11848.34392,12954.79101,18115.22313,18616.70691,19702.05581,19774.83687,22316.19287
24 | Pakistan,684.5971438,747.0835292,803.3427418,942.4082588,1049.938981,1175.921193,1443.429832,1704.686583,1971.829464,2049.350521,2092.712441,2605.94758
25 | Philippines,1272.880995,1547.944844,1649.552153,1814.12743,1989.37407,2373.204287,2603.273765,2189.634995,2279.324017,2536.534925,2650.921068,3190.481016
26 | Saudi Arabia,6459.554823,8157.591248,11626.41975,16903.04886,24837.42865,34167.7626,33693.17525,21198.26136,24841.61777,20586.69019,19014.54118,21654.83194
27 | Singapore,2315.138227,2843.104409,3674.735572,4977.41854,8597.756202,11210.08948,15169.16112,18861.53081,24769.8912,33519.4766,36023.1054,47143.17964
28 | Sri Lanka,1083.53203,1072.546602,1074.47196,1135.514326,1213.39553,1348.775651,1648.079789,1876.766827,2153.739222,2664.477257,3015.378833,3970.095407
29 | Syria,1643.485354,2117.234893,2193.037133,1881.923632,2571.423014,3195.484582,3761.837715,3116.774285,3340.542768,4014.238972,4090.925331,4184.548089
30 | Taiwan,1206.947913,1507.86129,1822.879028,2643.858681,4062.523897,5596.519826,7426.354774,11054.56175,15215.6579,20206.82098,23235.42329,28718.27684
31 | Thailand,757.7974177,793.5774148,1002.199172,1295.46066,1524.358936,1961.224635,2393.219781,2982.653773,4616.896545,5852.625497,5913.187529,7458.396327
32 | Vietnam,605.0664917,676.2854478,772.0491602,637.1232887,699.5016441,713.5371196,707.2357863,820.7994449,989.0231487,1385.896769,1764.456677,2441.576404
33 | West Bank and Gaza,1515.592329,1827.067742,2198.956312,2649.715007,3133.409277,3682.831494,4336.032082,5107.197384,6017.654756,7110.667619,4515.487575,3025.349798
34 | Yemen Rep.,781.7175761,804.8304547,825.6232006,862.4421463,1265.047031,1829.765177,1977.55701,1971.741538,1879.496673,2117.484526,2234.820827,2280.769906
35 |
--------------------------------------------------------------------------------
/Lecture 3/data/gapminder_gdp_europe.csv:
--------------------------------------------------------------------------------
1 | country,gdpPercap_1952,gdpPercap_1957,gdpPercap_1962,gdpPercap_1967,gdpPercap_1972,gdpPercap_1977,gdpPercap_1982,gdpPercap_1987,gdpPercap_1992,gdpPercap_1997,gdpPercap_2002,gdpPercap_2007
2 | Albania,1601.056136,1942.284244,2312.888958,2760.196931,3313.422188,3533.00391,3630.880722,3738.932735,2497.437901,3193.054604,4604.211737,5937.029526
3 | Austria,6137.076492,8842.59803,10750.72111,12834.6024,16661.6256,19749.4223,21597.08362,23687.82607,27042.01868,29095.92066,32417.60769,36126.4927
4 | Belgium,8343.105127,9714.960623,10991.20676,13149.04119,16672.14356,19117.97448,20979.84589,22525.56308,25575.57069,27561.19663,30485.88375,33692.60508
5 | Bosnia and Herzegovina,973.5331948,1353.989176,1709.683679,2172.352423,2860.16975,3528.481305,4126.613157,4314.114757,2546.781445,4766.355904,6018.975239,7446.298803
6 | Bulgaria,2444.286648,3008.670727,4254.337839,5577.0028,6597.494398,7612.240438,8224.191647,8239.854824,6302.623438,5970.38876,7696.777725,10680.79282
7 | Croatia,3119.23652,4338.231617,5477.890018,6960.297861,9164.090127,11305.38517,13221.82184,13822.58394,8447.794873,9875.604515,11628.38895,14619.22272
8 | Czech Republic,6876.14025,8256.343918,10136.86713,11399.44489,13108.4536,14800.16062,15377.22855,16310.4434,14297.02122,16048.51424,17596.21022,22833.30851
9 | Denmark,9692.385245,11099.65935,13583.31351,15937.21123,18866.20721,20422.9015,21688.04048,25116.17581,26406.73985,29804.34567,32166.50006,35278.41874
10 | Finland,6424.519071,7545.415386,9371.842561,10921.63626,14358.8759,15605.42283,18533.15761,21141.01223,20647.16499,23723.9502,28204.59057,33207.0844
11 | France,7029.809327,8662.834898,10560.48553,12999.91766,16107.19171,18292.63514,20293.89746,22066.44214,24703.79615,25889.78487,28926.03234,30470.0167
12 | Germany,7144.114393,10187.82665,12902.46291,14745.62561,18016.18027,20512.92123,22031.53274,24639.18566,26505.30317,27788.88416,30035.80198,32170.37442
13 | Greece,3530.690067,4916.299889,6017.190733,8513.097016,12724.82957,14195.52428,15268.42089,16120.52839,17541.49634,18747.69814,22514.2548,27538.41188
14 | Hungary,5263.673816,6040.180011,7550.359877,9326.64467,10168.65611,11674.83737,12545.99066,12986.47998,10535.62855,11712.7768,14843.93556,18008.94444
15 | Iceland,7267.688428,9244.001412,10350.15906,13319.89568,15798.06362,19654.96247,23269.6075,26923.20628,25144.39201,28061.09966,31163.20196,36180.78919
16 | Ireland,5210.280328,5599.077872,6631.597314,7655.568963,9530.772896,11150.98113,12618.32141,13872.86652,17558.81555,24521.94713,34077.04939,40675.99635
17 | Italy,4931.404155,6248.656232,8243.58234,10022.40131,12269.27378,14255.98475,16537.4835,19207.23482,22013.64486,24675.02446,27968.09817,28569.7197
18 | Montenegro,2647.585601,3682.259903,4649.593785,5907.850937,7778.414017,9595.929905,11222.58762,11732.51017,7003.339037,6465.613349,6557.194282,9253.896111
19 | Netherlands,8941.571858,11276.19344,12790.84956,15363.25136,18794.74567,21209.0592,21399.46046,23651.32361,26790.94961,30246.13063,33724.75778,36797.93332
20 | Norway,10095.42172,11653.97304,13450.40151,16361.87647,18965.05551,23311.34939,26298.63531,31540.9748,33965.66115,41283.16433,44683.97525,49357.19017
21 | Poland,4029.329699,4734.253019,5338.752143,6557.152776,8006.506993,9508.141454,8451.531004,9082.351172,7738.881247,10159.58368,12002.23908,15389.92468
22 | Portugal,3068.319867,3774.571743,4727.954889,6361.517993,9022.247417,10172.48572,11753.84291,13039.30876,16207.26663,17641.03156,19970.90787,20509.64777
23 | Romania,3144.613186,3943.370225,4734.997586,6470.866545,8011.414402,9356.39724,9605.314053,9696.273295,6598.409903,7346.547557,7885.360081,10808.47561
24 | Serbia,3581.459448,4981.090891,6289.629157,7991.707066,10522.06749,12980.66956,15181.0927,15870.87851,9325.068238,7914.320304,7236.075251,9786.534714
25 | Slovak Republic,5074.659104,6093.26298,7481.107598,8412.902397,9674.167626,10922.66404,11348.54585,12037.26758,9498.467723,12126.23065,13638.77837,18678.31435
26 | Slovenia,4215.041741,5862.276629,7402.303395,9405.489397,12383.4862,15277.03017,17866.72175,18678.53492,14214.71681,17161.10735,20660.01936,25768.25759
27 | Spain,3834.034742,4564.80241,5693.843879,7993.512294,10638.75131,13236.92117,13926.16997,15764.98313,18603.06452,20445.29896,24835.47166,28821.0637
28 | Sweden,8527.844662,9911.878226,12329.44192,15258.29697,17832.02464,18855.72521,20667.38125,23586.92927,23880.01683,25266.59499,29341.63093,33859.74835
29 | Switzerland,14734.23275,17909.48973,20431.0927,22966.14432,27195.11304,26982.29052,28397.71512,30281.70459,31871.5303,32135.32301,34480.95771,37506.41907
30 | Turkey,1969.10098,2218.754257,2322.869908,2826.356387,3450.69638,4269.122326,4241.356344,5089.043686,5678.348271,6601.429915,6508.085718,8458.276384
31 | United Kingdom,9979.508487,11283.17795,12477.17707,14142.85089,15895.11641,17428.74846,18232.42452,21664.78767,22705.09254,26074.53136,29478.99919,33203.26128
32 |
--------------------------------------------------------------------------------
/Lecture 3/data/gapminder_gdp_oceania.csv:
--------------------------------------------------------------------------------
1 | country,gdpPercap_1952,gdpPercap_1957,gdpPercap_1962,gdpPercap_1967,gdpPercap_1972,gdpPercap_1977,gdpPercap_1982,gdpPercap_1987,gdpPercap_1992,gdpPercap_1997,gdpPercap_2002,gdpPercap_2007
2 | Australia,10039.59564,10949.64959,12217.22686,14526.12465,16788.62948,18334.19751,19477.00928,21888.88903,23424.76683,26997.93657,30687.75473,34435.36744
3 | New Zealand,10556.57566,12247.39532,13175.678,14463.91893,16046.03728,16233.7177,17632.4104,19007.19129,18363.32494,21050.41377,23189.80135,25185.00911
4 |
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome.csv:
--------------------------------------------------------------------------------
1 | Taxon,Patient,Tissue,Stool
2 | Firmicutes,1,632,305
3 | Firmicutes,2,136,4182
4 | Firmicutes,3,1174,703
5 | Firmicutes,4,408,3946
6 | Firmicutes,5,831,8605
7 | Firmicutes,6,693,50
8 | Firmicutes,7,718,717
9 | Firmicutes,8,173,33
10 | Firmicutes,9,228,80
11 | Firmicutes,10,162,3196
12 | Firmicutes,11,372,32
13 | Firmicutes,12,4255,4361
14 | Firmicutes,13,107,1667
15 | Firmicutes,14,96,223
16 | Firmicutes,15,281,2377
17 | Proteobacteria,1,1638,3886
18 | Proteobacteria,2,2469,1821
19 | Proteobacteria,3,839,661
20 | Proteobacteria,4,4414,18
21 | Proteobacteria,5,12044,83
22 | Proteobacteria,6,2310,12
23 | Proteobacteria,7,3053,547
24 | Proteobacteria,8,395,2174
25 | Proteobacteria,9,2651,767
26 | Proteobacteria,10,1195,76
27 | Proteobacteria,11,6857,795
28 | Proteobacteria,12,483,666
29 | Proteobacteria,13,2950,3994
30 | Proteobacteria,14,1541,816
31 | Proteobacteria,15,1307,53
32 | Actinobacteria,1,569,648
33 | Actinobacteria,2,1590,4
34 | Actinobacteria,3,25,2
35 | Actinobacteria,4,259,300
36 | Actinobacteria,5,568,7
37 | Actinobacteria,6,1102,9
38 | Actinobacteria,7,678,377
39 | Actinobacteria,8,260,58
40 | Actinobacteria,9,424,233
41 | Actinobacteria,10,548,21
42 | Actinobacteria,11,201,83
43 | Actinobacteria,12,42,75
44 | Actinobacteria,13,109,59
45 | Actinobacteria,14,51,183
46 | Actinobacteria,15,310,204
47 | Bacteroidetes,1,115,380
48 | Bacteroidetes,2,67,0
49 | Bacteroidetes,3,0,0
50 | Bacteroidetes,4,85,5
51 | Bacteroidetes,5,143,7
52 | Bacteroidetes,6,678,2
53 | Bacteroidetes,7,4829,209
54 | Bacteroidetes,8,74,651
55 | Bacteroidetes,9,169,254
56 | Bacteroidetes,10,106,10
57 | Bacteroidetes,11,73,381
58 | Bacteroidetes,12,30,359
59 | Bacteroidetes,13,51,51
60 | Bacteroidetes,14,2473,2314
61 | Bacteroidetes,15,102,33
62 | Other,1,114,277
63 | Other,2,195,18
64 | Other,3,42,2
65 | Other,4,316,43
66 | Other,5,202,40
67 | Other,6,116,0
68 | Other,7,527,12
69 | Other,8,357,11
70 | Other,9,106,11
71 | Other,10,67,14
72 | Other,11,203,6
73 | Other,12,392,6
74 | Other,13,28,25
75 | Other,14,12,22
76 | Other,15,305,32
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome/MID1.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 3/data/microbiome/MID1.xls
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome/MID2.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 3/data/microbiome/MID2.xls
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome/MID3.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 3/data/microbiome/MID3.xls
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome/MID4.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 3/data/microbiome/MID4.xls
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome/MID5.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 3/data/microbiome/MID5.xls
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome/MID6.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 3/data/microbiome/MID6.xls
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome/MID7.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 3/data/microbiome/MID7.xls
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome/MID8.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 3/data/microbiome/MID8.xls
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome/MID9.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 3/data/microbiome/MID9.xls
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome/metadata.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 3/data/microbiome/metadata.xls
--------------------------------------------------------------------------------
/Lecture 3/data/microbiome_missing.csv:
--------------------------------------------------------------------------------
1 | Taxon,Patient,Tissue,Stool
2 | Firmicutes,1,632,305
3 | Firmicutes,2,136,4182
4 | Firmicutes,3,,703
5 | Firmicutes,4,408,3946
6 | Firmicutes,5,831,8605
7 | Firmicutes,6,693,50
8 | Firmicutes,7,718,717
9 | Firmicutes,8,173,33
10 | Firmicutes,9,228,NA
11 | Firmicutes,10,162,3196
12 | Firmicutes,11,372,-99999
13 | Firmicutes,12,4255,4361
14 | Firmicutes,13,107,1667
15 | Firmicutes,14,?,223
16 | Firmicutes,15,281,2377
17 | Proteobacteria,1,1638,3886
18 | Proteobacteria,2,2469,1821
19 | Proteobacteria,3,839,661
20 | Proteobacteria,4,4414,18
21 | Proteobacteria,5,12044,83
22 | Proteobacteria,6,2310,12
23 | Proteobacteria,7,3053,547
24 | Proteobacteria,8,395,2174
25 | Proteobacteria,9,2651,767
26 | Proteobacteria,10,1195,76
27 | Proteobacteria,11,6857,795
28 | Proteobacteria,12,483,666
29 | Proteobacteria,13,2950,3994
30 | Proteobacteria,14,1541,816
31 | Proteobacteria,15,1307,53
32 | Actinobacteria,1,569,648
33 | Actinobacteria,2,1590,4
34 | Actinobacteria,3,25,2
35 | Actinobacteria,4,259,300
36 | Actinobacteria,5,568,7
37 | Actinobacteria,6,1102,9
38 | Actinobacteria,7,678,377
39 | Actinobacteria,8,260,58
40 | Actinobacteria,9,424,233
41 | Actinobacteria,10,548,21
42 | Actinobacteria,11,201,83
43 | Actinobacteria,12,42,75
44 | Actinobacteria,13,109,59
45 | Actinobacteria,14,51,183
46 | Actinobacteria,15,310,204
47 | Bacteroidetes,1,115,380
48 | Bacteroidetes,2,67,0
49 | Bacteroidetes,3,0,0
50 | Bacteroidetes,4,85,5
51 | Bacteroidetes,5,143,7
52 | Bacteroidetes,6,678,2
53 | Bacteroidetes,7,4829,209
54 | Bacteroidetes,8,74,651
55 | Bacteroidetes,9,169,254
56 | Bacteroidetes,10,106,10
57 | Bacteroidetes,11,73,381
58 | Bacteroidetes,12,30,359
59 | Bacteroidetes,13,51,51
60 | Bacteroidetes,14,2473,2314
61 | Bacteroidetes,15,102,33
62 | Other,1,114,277
63 | Other,2,195,18
64 | Other,3,42,2
65 | Other,4,316,43
66 | Other,5,202,40
67 | Other,6,116,0
68 | Other,7,527,12
69 | Other,8,357,11
70 | Other,9,106,11
71 | Other,10,67,14
72 | Other,11,203,6
73 | Other,12,392,6
74 | Other,13,28,25
75 | Other,14,12,22
76 | Other,15,305,32
--------------------------------------------------------------------------------
/Lecture 4/Exercise 4.ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "markdown",
5 | "metadata": {},
6 | "source": [
7 | "# Exercise 4 - Pandas data munging"
8 | ]
9 | },
10 | {
11 | "cell_type": "code",
12 | "execution_count": null,
13 | "metadata": {
14 | "collapsed": true
15 | },
16 | "outputs": [],
17 | "source": [
18 | "import pandas as pd"
19 | ]
20 | },
21 | {
22 | "cell_type": "markdown",
23 | "metadata": {},
24 | "source": [
25 | "### Dealing with dates"
26 | ]
27 | },
28 | {
29 | "cell_type": "markdown",
30 | "metadata": {},
31 | "source": [
32 | "Start by reading in `data/gdp.csv`:"
33 | ]
34 | },
35 | {
36 | "cell_type": "code",
37 | "execution_count": null,
38 | "metadata": {
39 | "collapsed": true
40 | },
41 | "outputs": [],
42 | "source": [
43 | "gdp = "
44 | ]
45 | },
46 | {
47 | "cell_type": "markdown",
48 | "metadata": {},
49 | "source": [
50 | "Take a look at its contents"
51 | ]
52 | },
53 | {
54 | "cell_type": "code",
55 | "execution_count": null,
56 | "metadata": {
57 | "collapsed": false
58 | },
59 | "outputs": [],
60 | "source": []
61 | },
62 | {
63 | "cell_type": "markdown",
64 | "metadata": {},
65 | "source": [
66 | "What type is the `DATE` column?"
67 | ]
68 | },
69 | {
70 | "cell_type": "code",
71 | "execution_count": null,
72 | "metadata": {
73 | "collapsed": false
74 | },
75 | "outputs": [],
76 | "source": [
77 | "gdp"
78 | ]
79 | },
80 | {
81 | "cell_type": "markdown",
82 | "metadata": {},
83 | "source": [
84 | "Can you parse those into `datetime` format?\n",
85 | "\n",
86 | "_Hint_: `pd.to_...` and tab complete to see some possibilities..."
87 | ]
88 | },
89 | {
90 | "cell_type": "code",
91 | "execution_count": null,
92 | "metadata": {
93 | "collapsed": false
94 | },
95 | "outputs": [],
96 | "source": [
97 | "pd.to_"
98 | ]
99 | },
100 | {
101 | "cell_type": "markdown",
102 | "metadata": {},
103 | "source": [
104 | "Now look at the arguments for `pd.read_csv()` and figure out how to parse the dates automatically"
105 | ]
106 | },
107 | {
108 | "cell_type": "code",
109 | "execution_count": null,
110 | "metadata": {
111 | "collapsed": false
112 | },
113 | "outputs": [],
114 | "source": [
115 | "gdp = pd.read_csv(...)\n",
116 | "print(gdp.DATE.dtype)"
117 | ]
118 | },
119 | {
120 | "cell_type": "markdown",
121 | "metadata": {},
122 | "source": [
123 | "Take a look at [the docs](http://pandas.pydata.org/pandas-docs/stable/timeseries.html) at some point to see all of the things you can do with datetime..."
124 | ]
125 | },
126 | {
127 | "cell_type": "markdown",
128 | "metadata": {},
129 | "source": [
130 | "### Merging data\n",
131 | "\n",
132 | "Load in `data/gdp.csv` (Gross Domestic Product), `data/cpi.csv` (Consumer Price Index), and `data/rec.csv` (Recessions), being sure to parse the dates as you go\n",
133 | "\n",
134 | "_Note_: all three csvs are in the same format"
135 | ]
136 | },
137 | {
138 | "cell_type": "code",
139 | "execution_count": null,
140 | "metadata": {
141 | "collapsed": true
142 | },
143 | "outputs": [],
144 | "source": [
145 | "gdp = pd.read_csv(...)\n",
146 | "cpi = pd.read_csv(...)\n",
147 | "rec = pd.read_csv(...)"
148 | ]
149 | },
150 | {
151 | "cell_type": "markdown",
152 | "metadata": {},
153 | "source": [
154 | "Merge GDP and CPI into a single `DataFrame`"
155 | ]
156 | },
157 | {
158 | "cell_type": "code",
159 | "execution_count": null,
160 | "metadata": {
161 | "collapsed": false
162 | },
163 | "outputs": [],
164 | "source": [
165 | "data = \n",
166 | "data.head()"
167 | ]
168 | },
169 | {
170 | "cell_type": "markdown",
171 | "metadata": {},
172 | "source": [
173 | "Now add recessions onto the `DataFrame` (you should then have 4 columns - `DATE`, `GDP`, `CPIAUCSL`, and `USREC`):"
174 | ]
175 | },
176 | {
177 | "cell_type": "code",
178 | "execution_count": null,
179 | "metadata": {
180 | "collapsed": false
181 | },
182 | "outputs": [],
183 | "source": [
184 | "data = \n",
185 | "data.head()"
186 | ]
187 | },
188 | {
189 | "cell_type": "markdown",
190 | "metadata": {},
191 | "source": [
192 | "What's the correlation between GDP and CPI?"
193 | ]
194 | },
195 | {
196 | "cell_type": "code",
197 | "execution_count": null,
198 | "metadata": {
199 | "collapsed": false
200 | },
201 | "outputs": [],
202 | "source": [
203 | "data"
204 | ]
205 | },
206 | {
207 | "cell_type": "markdown",
208 | "metadata": {},
209 | "source": [
210 | "In how many periods was a recession recorded?"
211 | ]
212 | },
213 | {
214 | "cell_type": "code",
215 | "execution_count": null,
216 | "metadata": {
217 | "collapsed": false
218 | },
219 | "outputs": [],
220 | "source": [
221 | "data"
222 | ]
223 | },
224 | {
225 | "cell_type": "markdown",
226 | "metadata": {},
227 | "source": [
228 | "Get a list of all of the `DATE`s during which there was a recession (`USREC == 1`)"
229 | ]
230 | },
231 | {
232 | "cell_type": "code",
233 | "execution_count": null,
234 | "metadata": {
235 | "collapsed": false
236 | },
237 | "outputs": [],
238 | "source": [
239 | "recession_dates = \n",
240 | "recession_dates.head()"
241 | ]
242 | },
243 | {
244 | "cell_type": "markdown",
245 | "metadata": {},
246 | "source": [
247 | "Find the unique years in which there was a recession\n",
248 | "\n",
249 | "_Hint_: Look at the methods of `recession_dates.dt.` (hit tab complete)"
250 | ]
251 | },
252 | {
253 | "cell_type": "code",
254 | "execution_count": null,
255 | "metadata": {
256 | "collapsed": false
257 | },
258 | "outputs": [],
259 | "source": [
260 | "years = recession_dates.dt.\n",
261 | "print(years[0:10])"
262 | ]
263 | },
264 | {
265 | "cell_type": "code",
266 | "execution_count": null,
267 | "metadata": {
268 | "collapsed": false
269 | },
270 | "outputs": [],
271 | "source": [
272 | "unique_years = \n",
273 | "print(unique_years)"
274 | ]
275 | },
276 | {
277 | "cell_type": "markdown",
278 | "metadata": {},
279 | "source": [
280 | "### Reshaping data\n",
281 | "\n",
282 | "Start by adding separate `year` and `month` columns to the data:"
283 | ]
284 | },
285 | {
286 | "cell_type": "code",
287 | "execution_count": null,
288 | "metadata": {
289 | "collapsed": false
290 | },
291 | "outputs": [],
292 | "source": [
293 | "data['year'] = ...\n",
294 | "data['month'] = ...\n",
295 | "data.head()"
296 | ]
297 | },
298 | {
299 | "cell_type": "markdown",
300 | "metadata": {},
301 | "source": [
302 | "Index the data by `year` and `month`"
303 | ]
304 | },
305 | {
306 | "cell_type": "code",
307 | "execution_count": null,
308 | "metadata": {
309 | "collapsed": false
310 | },
311 | "outputs": [],
312 | "source": [
313 | "data_indexed = ...\n",
314 | "data_indexed.head()"
315 | ]
316 | },
317 | {
318 | "cell_type": "markdown",
319 | "metadata": {},
320 | "source": [
321 | "Drop the superfluous `DATE` column"
322 | ]
323 | },
324 | {
325 | "cell_type": "code",
326 | "execution_count": null,
327 | "metadata": {
328 | "collapsed": false
329 | },
330 | "outputs": [],
331 | "source": [
332 | "data_indexed\n",
333 | "data_indexed.head()"
334 | ]
335 | },
336 | {
337 | "cell_type": "markdown",
338 | "metadata": {},
339 | "source": [
340 | "Use `.stack()` to create a long version of the data:"
341 | ]
342 | },
343 | {
344 | "cell_type": "code",
345 | "execution_count": null,
346 | "metadata": {
347 | "collapsed": false
348 | },
349 | "outputs": [],
350 | "source": [
351 | "long = data_indexed...\n",
352 | "long.head()"
353 | ]
354 | },
355 | {
356 | "cell_type": "markdown",
357 | "metadata": {},
358 | "source": [
359 | "And then use `.unstack()` to make the data wide, with one column per month\n",
360 | "\n",
361 | "_Hint_: you need to pass an argument to `.unstack()` to identify which variable to make wide"
362 | ]
363 | },
364 | {
365 | "cell_type": "code",
366 | "execution_count": null,
367 | "metadata": {
368 | "collapsed": true
369 | },
370 | "outputs": [],
371 | "source": [
372 | "long.unstack?"
373 | ]
374 | },
375 | {
376 | "cell_type": "code",
377 | "execution_count": null,
378 | "metadata": {
379 | "collapsed": false
380 | },
381 | "outputs": [],
382 | "source": [
383 | "wide = long...\n",
384 | "wide.head()"
385 | ]
386 | },
387 | {
388 | "cell_type": "markdown",
389 | "metadata": {},
390 | "source": [
391 | "Try using `data.pivot()` to produce a data frame that looks like:\n",
392 | "- A row for each year\n",
393 | "- One column per month\n",
394 | "- Values filled in with the GDP of the corresonding year/month"
395 | ]
396 | },
397 | {
398 | "cell_type": "code",
399 | "execution_count": null,
400 | "metadata": {
401 | "collapsed": false
402 | },
403 | "outputs": [],
404 | "source": [
405 | "data.pivot(...).head()"
406 | ]
407 | }
408 | ],
409 | "metadata": {
410 | "anaconda-cloud": {},
411 | "kernelspec": {
412 | "display_name": "Python [conda root]",
413 | "language": "python",
414 | "name": "conda-root-py"
415 | },
416 | "language_info": {
417 | "codemirror_mode": {
418 | "name": "ipython",
419 | "version": 3
420 | },
421 | "file_extension": ".py",
422 | "mimetype": "text/x-python",
423 | "name": "python",
424 | "nbconvert_exporter": "python",
425 | "pygments_lexer": "ipython3",
426 | "version": "3.5.2"
427 | }
428 | },
429 | "nbformat": 4,
430 | "nbformat_minor": 1
431 | }
432 |
--------------------------------------------------------------------------------
/Lecture 4/data/beer_subset.csv.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 4/data/beer_subset.csv.gz
--------------------------------------------------------------------------------
/Lecture 4/data/cdystonia.csv:
--------------------------------------------------------------------------------
1 | patient,obs,week,site,id,treat,age,sex,twstrs
2 | 1,1,0,1,1,5000U,65,F,32
3 | 1,2,2,1,1,5000U,65,F,30
4 | 1,3,4,1,1,5000U,65,F,24
5 | 1,4,8,1,1,5000U,65,F,37
6 | 1,5,12,1,1,5000U,65,F,39
7 | 1,6,16,1,1,5000U,65,F,36
8 | 2,1,0,1,2,10000U,70,F,60
9 | 2,2,2,1,2,10000U,70,F,26
10 | 2,3,4,1,2,10000U,70,F,27
11 | 2,4,8,1,2,10000U,70,F,41
12 | 2,5,12,1,2,10000U,70,F,65
13 | 2,6,16,1,2,10000U,70,F,67
14 | 3,1,0,1,3,5000U,64,F,44
15 | 3,2,2,1,3,5000U,64,F,20
16 | 3,3,4,1,3,5000U,64,F,23
17 | 3,4,8,1,3,5000U,64,F,26
18 | 3,5,12,1,3,5000U,64,F,35
19 | 3,6,16,1,3,5000U,64,F,35
20 | 4,1,0,1,4,Placebo,59,F,53
21 | 4,2,2,1,4,Placebo,59,F,61
22 | 4,3,4,1,4,Placebo,59,F,64
23 | 4,4,8,1,4,Placebo,59,F,62
24 | 5,1,0,1,5,10000U,76,F,53
25 | 5,2,2,1,5,10000U,76,F,35
26 | 5,3,4,1,5,10000U,76,F,48
27 | 5,4,8,1,5,10000U,76,F,49
28 | 5,5,12,1,5,10000U,76,F,41
29 | 5,6,16,1,5,10000U,76,F,51
30 | 6,1,0,1,6,10000U,59,F,49
31 | 6,2,2,1,6,10000U,59,F,34
32 | 6,3,4,1,6,10000U,59,F,43
33 | 6,4,8,1,6,10000U,59,F,48
34 | 6,5,12,1,6,10000U,59,F,48
35 | 6,6,16,1,6,10000U,59,F,51
36 | 7,1,0,1,7,5000U,72,M,42
37 | 7,2,2,1,7,5000U,72,M,32
38 | 7,3,4,1,7,5000U,72,M,32
39 | 7,4,8,1,7,5000U,72,M,43
40 | 7,5,12,1,7,5000U,72,M,42
41 | 7,6,16,1,7,5000U,72,M,46
42 | 8,1,0,1,8,Placebo,40,M,34
43 | 8,2,2,1,8,Placebo,40,M,33
44 | 8,3,4,1,8,Placebo,40,M,21
45 | 8,4,8,1,8,Placebo,40,M,27
46 | 8,5,12,1,8,Placebo,40,M,32
47 | 8,6,16,1,8,Placebo,40,M,38
48 | 9,1,0,1,9,5000U,52,F,41
49 | 9,2,2,1,9,5000U,52,F,32
50 | 9,3,4,1,9,5000U,52,F,34
51 | 9,4,8,1,9,5000U,52,F,35
52 | 9,5,12,1,9,5000U,52,F,37
53 | 9,6,16,1,9,5000U,52,F,36
54 | 10,1,0,1,10,Placebo,47,M,27
55 | 10,2,2,1,10,Placebo,47,M,10
56 | 10,3,4,1,10,Placebo,47,M,31
57 | 10,4,8,1,10,Placebo,47,M,32
58 | 10,5,12,1,10,Placebo,47,M,6
59 | 10,6,16,1,10,Placebo,47,M,14
60 | 11,1,0,1,11,10000U,57,F,48
61 | 11,2,2,1,11,10000U,57,F,41
62 | 11,3,4,1,11,10000U,57,F,32
63 | 11,4,8,1,11,10000U,57,F,35
64 | 11,5,12,1,11,10000U,57,F,57
65 | 11,6,16,1,11,10000U,57,F,51
66 | 12,1,0,1,12,Placebo,47,F,34
67 | 12,2,2,1,12,Placebo,47,F,19
68 | 12,3,4,1,12,Placebo,47,F,21
69 | 12,4,8,1,12,Placebo,47,F,24
70 | 12,5,12,1,12,Placebo,47,F,28
71 | 12,6,16,1,12,Placebo,47,F,28
72 | 13,1,0,2,1,Placebo,70,F,49
73 | 13,2,2,2,1,Placebo,70,F,47
74 | 13,3,4,2,1,Placebo,70,F,44
75 | 13,4,8,2,1,Placebo,70,F,48
76 | 13,5,12,2,1,Placebo,70,F,44
77 | 13,6,16,2,1,Placebo,70,F,44
78 | 14,1,0,2,2,5000U,49,F,46
79 | 14,2,2,2,2,5000U,49,F,35
80 | 14,3,4,2,2,5000U,49,F,45
81 | 14,4,8,2,2,5000U,49,F,49
82 | 14,5,12,2,2,5000U,49,F,53
83 | 14,6,16,2,2,5000U,49,F,56
84 | 15,1,0,2,3,10000U,59,F,56
85 | 15,2,2,2,3,10000U,59,F,44
86 | 15,3,4,2,3,10000U,59,F,48
87 | 15,4,8,2,3,10000U,59,F,54
88 | 15,5,12,2,3,10000U,59,F,49
89 | 15,6,16,2,3,10000U,59,F,60
90 | 16,1,0,2,4,5000U,64,M,59
91 | 16,2,2,2,4,5000U,64,M,48
92 | 16,3,4,2,4,5000U,64,M,56
93 | 16,4,8,2,4,5000U,64,M,55
94 | 16,5,12,2,4,5000U,64,M,57
95 | 16,6,16,2,4,5000U,64,M,58
96 | 17,1,0,2,5,10000U,45,F,62
97 | 17,2,2,2,5,10000U,45,F,60
98 | 17,3,4,2,5,10000U,45,F,60
99 | 17,4,8,2,5,10000U,45,F,64
100 | 17,5,12,2,5,10000U,45,F,67
101 | 17,6,16,2,5,10000U,45,F,66
102 | 18,1,0,2,6,Placebo,66,F,50
103 | 18,2,2,2,6,Placebo,66,F,53
104 | 18,3,4,2,6,Placebo,66,F,52
105 | 18,4,8,2,6,Placebo,66,F,57
106 | 18,5,12,2,6,Placebo,66,F,61
107 | 18,6,16,2,6,Placebo,66,F,54
108 | 19,1,0,2,7,10000U,49,F,42
109 | 19,2,2,2,7,10000U,49,F,42
110 | 19,3,4,2,7,10000U,49,F,43
111 | 19,4,8,2,7,10000U,49,F,33
112 | 19,5,12,2,7,10000U,49,F,37
113 | 19,6,16,2,7,10000U,49,F,43
114 | 20,1,0,2,8,Placebo,54,F,53
115 | 20,2,2,2,8,Placebo,54,F,56
116 | 20,3,4,2,8,Placebo,54,F,52
117 | 20,4,8,2,8,Placebo,54,F,54
118 | 20,5,12,2,8,Placebo,54,F,55
119 | 20,6,16,2,8,Placebo,54,F,51
120 | 21,1,0,2,9,5000U,47,F,67
121 | 21,2,2,2,9,5000U,47,F,64
122 | 21,3,4,2,9,5000U,47,F,65
123 | 21,4,8,2,9,5000U,47,F,64
124 | 21,5,12,2,9,5000U,47,F,62
125 | 21,6,16,2,9,5000U,47,F,64
126 | 22,1,0,2,10,Placebo,31,M,44
127 | 22,2,2,2,10,Placebo,31,M,40
128 | 22,3,4,2,10,Placebo,31,M,32
129 | 22,4,8,2,10,Placebo,31,M,36
130 | 22,5,12,2,10,Placebo,31,M,42
131 | 22,6,16,2,10,Placebo,31,M,43
132 | 23,1,0,2,11,10000U,53,F,65
133 | 23,2,2,2,11,10000U,53,F,58
134 | 23,3,4,2,11,10000U,53,F,55
135 | 23,5,12,2,11,10000U,53,F,56
136 | 23,6,16,2,11,10000U,53,F,60
137 | 24,1,0,2,12,5000U,61,M,56
138 | 24,2,2,2,12,5000U,61,M,54
139 | 24,3,4,2,12,5000U,61,M,52
140 | 24,4,8,2,12,5000U,61,M,48
141 | 24,5,12,2,12,5000U,61,M,52
142 | 24,6,16,2,12,5000U,61,M,53
143 | 25,1,0,2,13,Placebo,40,M,30
144 | 25,2,2,2,13,Placebo,40,M,33
145 | 25,3,4,2,13,Placebo,40,M,25
146 | 25,4,8,2,13,Placebo,40,M,29
147 | 25,5,12,2,13,Placebo,40,M,32
148 | 25,6,16,2,13,Placebo,40,M,32
149 | 26,1,0,2,14,5000U,67,M,47
150 | 26,3,4,2,14,5000U,67,M,54
151 | 26,4,8,2,14,5000U,67,M,43
152 | 26,5,12,2,14,5000U,67,M,46
153 | 26,6,16,2,14,5000U,67,M,50
154 | 27,1,0,3,1,10000U,54,F,50
155 | 27,2,2,3,1,10000U,54,F,43
156 | 27,3,4,3,1,10000U,54,F,51
157 | 27,4,8,3,1,10000U,54,F,46
158 | 27,5,12,3,1,10000U,54,F,49
159 | 27,6,16,3,1,10000U,54,F,53
160 | 28,1,0,3,2,Placebo,41,F,34
161 | 28,2,2,3,2,Placebo,41,F,29
162 | 28,3,4,3,2,Placebo,41,F,27
163 | 28,4,8,3,2,Placebo,41,F,21
164 | 28,5,12,3,2,Placebo,41,F,22
165 | 28,6,16,3,2,Placebo,41,F,22
166 | 29,1,0,3,3,5000U,66,M,39
167 | 29,2,2,3,3,5000U,66,M,41
168 | 29,3,4,3,3,5000U,66,M,33
169 | 29,4,8,3,3,5000U,66,M,39
170 | 29,5,12,3,3,5000U,66,M,37
171 | 29,6,16,3,3,5000U,66,M,37
172 | 30,1,0,3,4,Placebo,68,F,43
173 | 30,2,2,3,4,Placebo,68,F,31
174 | 30,3,4,3,4,Placebo,68,F,29
175 | 30,4,8,3,4,Placebo,68,F,28
176 | 30,5,12,3,4,Placebo,68,F,33
177 | 30,6,16,3,4,Placebo,68,F,38
178 | 31,1,0,3,5,10000U,41,F,46
179 | 31,2,2,3,5,10000U,41,F,26
180 | 31,3,4,3,5,10000U,41,F,29
181 | 31,4,8,3,5,10000U,41,F,33
182 | 31,5,12,3,5,10000U,41,F,45
183 | 31,6,16,3,5,10000U,41,F,56
184 | 32,1,0,3,6,5000U,77,M,52
185 | 32,2,2,3,6,5000U,77,M,44
186 | 32,3,4,3,6,5000U,77,M,47
187 | 32,4,8,3,6,5000U,77,M,50
188 | 32,5,12,3,6,5000U,77,M,50
189 | 32,6,16,3,6,5000U,77,M,49
190 | 33,1,0,3,7,10000U,41,M,38
191 | 33,2,2,3,7,10000U,41,M,19
192 | 33,3,4,3,7,10000U,41,M,20
193 | 33,4,8,3,7,10000U,41,M,27
194 | 33,5,12,3,7,10000U,41,M,29
195 | 33,6,16,3,7,10000U,41,M,32
196 | 34,1,0,3,8,Placebo,56,M,33
197 | 34,2,2,3,8,Placebo,56,M,38
198 | 34,3,4,3,8,Placebo,56,M,40
199 | 34,4,8,3,8,Placebo,56,M,48
200 | 34,5,12,3,8,Placebo,56,M,49
201 | 34,6,16,3,8,Placebo,56,M,44
202 | 35,1,0,3,9,5000U,46,F,28
203 | 35,2,2,3,9,5000U,46,F,16
204 | 35,3,4,3,9,5000U,46,F,11
205 | 35,4,8,3,9,5000U,46,F,7
206 | 35,5,12,3,9,5000U,46,F,13
207 | 35,6,16,3,9,5000U,46,F,21
208 | 36,1,0,3,10,10000U,46,F,34
209 | 36,2,2,3,10,10000U,46,F,23
210 | 36,3,4,3,10,10000U,46,F,16
211 | 36,4,8,3,10,10000U,46,F,15
212 | 36,5,12,3,10,10000U,46,F,17
213 | 36,6,16,3,10,10000U,46,F,29
214 | 37,1,0,3,11,Placebo,47,F,39
215 | 37,2,2,3,11,Placebo,47,F,37
216 | 37,3,4,3,11,Placebo,47,F,39
217 | 37,4,8,3,11,Placebo,47,F,39
218 | 37,5,12,3,11,Placebo,47,F,45
219 | 37,6,16,3,11,Placebo,47,F,43
220 | 38,1,0,3,12,5000U,35,M,29
221 | 38,2,2,3,12,5000U,35,M,42
222 | 38,3,4,3,12,5000U,35,M,35
223 | 38,4,8,3,12,5000U,35,M,24
224 | 38,5,12,3,12,5000U,35,M,29
225 | 38,6,16,3,12,5000U,35,M,42
226 | 39,1,0,4,1,Placebo,58,M,52
227 | 39,2,2,4,1,Placebo,58,M,55
228 | 39,3,4,4,1,Placebo,58,M,51
229 | 39,4,8,4,1,Placebo,58,M,52
230 | 39,5,12,4,1,Placebo,58,M,54
231 | 39,6,16,4,1,Placebo,58,M,57
232 | 40,1,0,4,2,5000U,62,F,52
233 | 40,2,2,4,2,5000U,62,F,30
234 | 40,3,4,4,2,5000U,62,F,43
235 | 40,4,8,4,2,5000U,62,F,45
236 | 40,5,12,4,2,5000U,62,F,47
237 | 40,6,16,4,2,5000U,62,F,46
238 | 41,1,0,4,3,10000U,73,F,54
239 | 41,2,2,4,3,10000U,73,F,52
240 | 41,3,4,4,3,10000U,73,F,52
241 | 41,4,8,4,3,10000U,73,F,54
242 | 41,5,12,4,3,10000U,73,F,51
243 | 41,6,16,4,3,10000U,73,F,57
244 | 42,1,0,4,4,10000U,52,F,52
245 | 42,2,2,4,4,10000U,52,F,44
246 | 42,3,4,4,4,10000U,52,F,33
247 | 42,4,8,4,4,10000U,52,F,54
248 | 42,5,12,4,4,10000U,52,F,46
249 | 42,6,16,4,4,10000U,52,F,47
250 | 43,1,0,4,5,Placebo,53,F,47
251 | 43,2,2,4,5,Placebo,53,F,45
252 | 43,3,4,4,5,Placebo,53,F,41
253 | 43,4,8,4,5,Placebo,53,F,45
254 | 43,5,12,4,5,Placebo,53,F,43
255 | 43,6,16,4,5,Placebo,53,F,41
256 | 44,1,0,4,6,5000U,69,M,44
257 | 44,2,2,4,6,5000U,69,M,34
258 | 44,3,4,4,6,5000U,69,M,29
259 | 44,4,8,4,6,5000U,69,M,28
260 | 44,5,12,4,6,5000U,69,M,35
261 | 44,6,16,4,6,5000U,69,M,41
262 | 45,1,0,4,7,Placebo,55,M,42
263 | 45,2,2,4,7,Placebo,55,M,39
264 | 45,3,4,4,7,Placebo,55,M,38
265 | 45,4,8,4,7,Placebo,55,M,47
266 | 45,5,12,4,7,Placebo,55,M,39
267 | 45,6,16,4,7,Placebo,55,M,39
268 | 46,1,0,4,8,10000U,52,F,42
269 | 46,2,2,4,8,10000U,52,F,14
270 | 46,3,4,4,8,10000U,52,F,9
271 | 46,4,8,4,8,10000U,52,F,9
272 | 46,5,12,4,8,10000U,52,F,16
273 | 46,6,16,4,8,10000U,52,F,33
274 | 47,1,0,5,1,10000U,51,F,44
275 | 47,2,2,5,1,10000U,51,F,34
276 | 47,3,4,5,1,10000U,51,F,32
277 | 47,4,8,5,1,10000U,51,F,35
278 | 47,5,12,5,1,10000U,51,F,54
279 | 47,6,16,5,1,10000U,51,F,53
280 | 48,1,0,5,2,Placebo,56,F,60
281 | 48,2,2,5,2,Placebo,56,F,57
282 | 48,3,4,5,2,Placebo,56,F,53
283 | 48,4,8,5,2,Placebo,56,F,52
284 | 48,5,12,5,2,Placebo,56,F,53
285 | 48,6,16,5,2,Placebo,56,F,58
286 | 49,1,0,5,3,5000U,65,F,60
287 | 49,2,2,5,3,5000U,65,F,53
288 | 49,3,4,5,3,5000U,65,F,55
289 | 49,4,8,5,3,5000U,65,F,62
290 | 49,5,12,5,3,5000U,65,F,67
291 | 50,1,0,5,4,10000U,35,F,50
292 | 50,2,2,5,4,10000U,35,F,50
293 | 50,4,8,5,4,10000U,35,F,46
294 | 50,5,12,5,4,10000U,35,F,50
295 | 50,6,16,5,4,10000U,35,F,57
296 | 51,1,0,5,5,5000U,43,M,38
297 | 51,2,2,5,5,5000U,43,M,27
298 | 51,3,4,5,5,5000U,43,M,16
299 | 51,4,8,5,5,5000U,43,M,19
300 | 51,5,12,5,5,5000U,43,M,23
301 | 51,6,16,5,5,5000U,43,M,26
302 | 52,1,0,5,6,Placebo,61,M,44
303 | 52,3,4,5,6,Placebo,61,M,46
304 | 52,4,8,5,6,Placebo,61,M,26
305 | 52,5,12,5,6,Placebo,61,M,30
306 | 52,6,16,5,6,Placebo,61,M,34
307 | 53,1,0,6,1,Placebo,43,M,54
308 | 53,2,2,6,1,Placebo,43,M,53
309 | 53,3,4,6,1,Placebo,43,M,51
310 | 53,4,8,6,1,Placebo,43,M,56
311 | 53,5,12,6,1,Placebo,43,M,39
312 | 53,6,16,6,1,Placebo,43,M,9
313 | 54,1,0,6,2,10000U,64,F,54
314 | 54,2,2,6,2,10000U,64,F,32
315 | 54,3,4,6,2,10000U,64,F,40
316 | 54,4,8,6,2,10000U,64,F,52
317 | 54,5,12,6,2,10000U,64,F,42
318 | 54,6,16,6,2,10000U,64,F,47
319 | 55,1,0,6,3,5000U,57,M,56
320 | 55,2,2,6,3,5000U,57,M,55
321 | 55,3,4,6,3,5000U,57,M,44
322 | 55,4,8,6,3,5000U,57,M,50
323 | 55,5,12,6,3,5000U,57,M,53
324 | 55,6,16,6,3,5000U,57,M,52
325 | 56,1,0,6,4,5000U,60,F,51
326 | 56,2,2,6,4,5000U,60,F,50
327 | 56,3,4,6,4,5000U,60,F,50
328 | 56,4,8,6,4,5000U,60,F,56
329 | 56,5,12,6,4,5000U,60,F,59
330 | 56,6,16,6,4,5000U,60,F,53
331 | 57,1,0,6,5,10000U,44,F,53
332 | 57,2,2,6,5,10000U,44,F,56
333 | 57,3,4,6,5,10000U,44,F,47
334 | 57,4,8,6,5,10000U,44,F,53
335 | 57,5,12,6,5,10000U,44,F,51
336 | 57,6,16,6,5,10000U,44,F,51
337 | 58,1,0,6,6,Placebo,41,F,36
338 | 58,2,2,6,6,Placebo,41,F,29
339 | 58,3,4,6,6,Placebo,41,F,24
340 | 58,4,8,6,6,Placebo,41,F,32
341 | 58,5,12,6,6,Placebo,41,F,45
342 | 58,6,16,6,6,Placebo,41,F,36
343 | 59,1,0,6,7,5000U,51,F,59
344 | 59,2,2,6,7,5000U,51,F,53
345 | 59,3,4,6,7,5000U,51,F,45
346 | 59,4,8,6,7,5000U,51,F,44
347 | 59,5,12,6,7,5000U,51,F,50
348 | 59,6,16,6,7,5000U,51,F,48
349 | 60,1,0,6,8,Placebo,57,F,49
350 | 60,2,2,6,8,Placebo,57,F,50
351 | 60,3,4,6,8,Placebo,57,F,48
352 | 60,4,8,6,8,Placebo,57,F,56
353 | 60,5,12,6,8,Placebo,57,F,49
354 | 60,6,16,6,8,Placebo,57,F,57
355 | 61,1,0,6,9,10000U,42,F,50
356 | 61,2,2,6,9,10000U,42,F,38
357 | 61,3,4,6,9,10000U,42,F,42
358 | 61,4,8,6,9,10000U,42,F,43
359 | 61,5,12,6,9,10000U,42,F,42
360 | 61,6,16,6,9,10000U,42,F,46
361 | 62,1,0,6,10,Placebo,48,F,46
362 | 62,2,2,6,10,Placebo,48,F,48
363 | 62,3,4,6,10,Placebo,48,F,46
364 | 62,4,8,6,10,Placebo,48,F,57
365 | 62,5,12,6,10,Placebo,48,F,57
366 | 62,6,16,6,10,Placebo,48,F,49
367 | 63,1,0,6,11,10000U,57,M,55
368 | 63,2,2,6,11,10000U,57,M,34
369 | 63,3,4,6,11,10000U,57,M,26
370 | 63,4,8,6,11,10000U,57,M,40
371 | 63,5,12,6,11,10000U,57,M,49
372 | 63,6,16,6,11,10000U,57,M,47
373 | 64,1,0,6,12,5000U,39,M,46
374 | 64,2,2,6,12,5000U,39,M,44
375 | 64,3,4,6,12,5000U,39,M,47
376 | 64,4,8,6,12,5000U,39,M,50
377 | 64,5,12,6,12,5000U,39,M,46
378 | 64,6,16,6,12,5000U,39,M,51
379 | 65,1,0,6,13,10000U,67,M,34
380 | 65,2,2,6,13,10000U,67,M,31
381 | 65,3,4,6,13,10000U,67,M,25
382 | 66,1,0,6,14,5000U,39,F,57
383 | 66,2,2,6,14,5000U,39,F,48
384 | 66,3,4,6,14,5000U,39,F,50
385 | 66,4,8,6,14,5000U,39,F,50
386 | 66,5,12,6,14,5000U,39,F,50
387 | 66,6,16,6,14,5000U,39,F,49
388 | 67,1,0,6,15,Placebo,69,M,41
389 | 67,2,2,6,15,Placebo,69,M,40
390 | 67,3,4,6,15,Placebo,69,M,42
391 | 67,4,8,6,15,Placebo,69,M,38
392 | 67,5,12,6,15,Placebo,69,M,50
393 | 67,6,16,6,15,Placebo,69,M,56
394 | 68,1,0,7,1,5000U,54,F,49
395 | 68,2,2,7,1,5000U,54,F,25
396 | 68,3,4,7,1,5000U,54,F,30
397 | 68,4,8,7,1,5000U,54,F,41
398 | 68,5,12,7,1,5000U,54,F,41
399 | 68,6,16,7,1,5000U,54,F,31
400 | 69,1,0,7,2,Placebo,67,F,42
401 | 69,2,2,7,2,Placebo,67,F,30
402 | 69,3,4,7,2,Placebo,67,F,40
403 | 69,4,8,7,2,Placebo,67,F,43
404 | 69,5,12,7,2,Placebo,67,F,36
405 | 69,6,16,7,2,Placebo,67,F,45
406 | 70,1,0,7,3,10000U,58,F,31
407 | 70,2,2,7,3,10000U,58,F,18
408 | 70,3,4,7,3,10000U,58,F,23
409 | 70,4,8,7,3,10000U,58,F,26
410 | 70,5,12,7,3,10000U,58,F,33
411 | 70,6,16,7,3,10000U,58,F,41
412 | 71,1,0,7,4,Placebo,72,F,50
413 | 71,2,2,7,4,Placebo,72,F,27
414 | 71,3,4,7,4,Placebo,72,F,43
415 | 71,4,8,7,4,Placebo,72,F,32
416 | 71,5,12,7,4,Placebo,72,F,40
417 | 71,6,16,7,4,Placebo,72,F,47
418 | 72,1,0,7,5,10000U,65,F,35
419 | 72,2,2,7,5,10000U,65,F,24
420 | 72,3,4,7,5,10000U,65,F,34
421 | 72,4,8,7,5,10000U,65,F,28
422 | 72,5,12,7,5,10000U,65,F,34
423 | 72,6,16,7,5,10000U,65,F,28
424 | 73,1,0,7,6,5000U,68,F,38
425 | 73,2,2,7,6,5000U,68,F,25
426 | 73,3,4,7,6,5000U,68,F,21
427 | 73,4,8,7,6,5000U,68,F,33
428 | 73,5,12,7,6,5000U,68,F,42
429 | 73,6,16,7,6,5000U,68,F,53
430 | 74,1,0,7,7,10000U,75,F,53
431 | 74,2,2,7,7,10000U,75,F,40
432 | 74,3,4,7,7,10000U,75,F,38
433 | 74,4,8,7,7,10000U,75,F,44
434 | 74,5,12,7,7,10000U,75,F,47
435 | 74,6,16,7,7,10000U,75,F,53
436 | 75,1,0,7,8,Placebo,26,F,42
437 | 75,2,2,7,8,Placebo,26,F,48
438 | 75,3,4,7,8,Placebo,26,F,26
439 | 75,4,8,7,8,Placebo,26,F,37
440 | 75,5,12,7,8,Placebo,26,F,37
441 | 75,6,16,7,8,Placebo,26,F,43
442 | 76,1,0,7,9,5000U,36,F,53
443 | 76,2,2,7,9,5000U,36,F,45
444 | 76,3,4,7,9,5000U,36,F,52
445 | 76,4,8,7,9,5000U,36,F,51
446 | 76,5,12,7,9,5000U,36,F,52
447 | 76,6,16,7,9,5000U,36,F,53
448 | 77,1,0,7,10,10000U,72,M,46
449 | 77,2,2,7,10,10000U,72,M,47
450 | 77,3,4,7,10,10000U,72,M,45
451 | 77,4,8,7,10,10000U,72,M,45
452 | 77,5,12,7,10,10000U,72,M,50
453 | 77,6,16,7,10,10000U,72,M,52
454 | 78,1,0,7,11,Placebo,54,F,50
455 | 78,2,2,7,11,Placebo,54,F,42
456 | 78,3,4,7,11,Placebo,54,F,52
457 | 78,4,8,7,11,Placebo,54,F,60
458 | 78,5,12,7,11,Placebo,54,F,54
459 | 78,6,16,7,11,Placebo,54,F,59
460 | 79,1,0,7,12,5000U,64,F,43
461 | 79,2,2,7,12,5000U,64,F,24
462 | 79,3,4,7,12,5000U,64,F,17
463 | 79,4,8,7,12,5000U,64,F,37
464 | 79,5,12,7,12,5000U,64,F,36
465 | 79,6,16,7,12,5000U,64,F,38
466 | 80,1,0,8,1,Placebo,39,F,46
467 | 80,2,2,8,1,Placebo,39,F,39
468 | 80,3,4,8,1,Placebo,39,F,25
469 | 80,4,8,8,1,Placebo,39,F,15
470 | 80,5,12,8,1,Placebo,39,F,21
471 | 80,6,16,8,1,Placebo,39,F,25
472 | 81,1,0,8,2,10000U,54,M,41
473 | 81,2,2,8,2,10000U,54,M,30
474 | 81,3,4,8,2,10000U,54,M,44
475 | 81,4,8,8,2,10000U,54,M,46
476 | 81,5,12,8,2,10000U,54,M,46
477 | 81,6,16,8,2,10000U,54,M,44
478 | 82,1,0,8,3,5000U,48,M,33
479 | 82,2,2,8,3,5000U,48,M,27
480 | 82,3,4,8,3,5000U,48,M,25
481 | 82,4,8,8,3,5000U,48,M,30
482 | 82,5,12,8,3,5000U,48,M,28
483 | 82,6,16,8,3,5000U,48,M,30
484 | 83,1,0,8,4,5000U,83,F,36
485 | 83,2,2,8,4,5000U,83,F,15
486 | 83,3,4,8,4,5000U,83,F,16
487 | 83,4,8,8,4,5000U,83,F,17
488 | 83,5,12,8,4,5000U,83,F,22
489 | 83,6,16,8,4,5000U,83,F,41
490 | 84,1,0,8,5,10000U,74,M,33
491 | 84,2,2,8,5,10000U,74,M,32
492 | 84,3,4,8,5,10000U,74,M,31
493 | 84,4,8,8,5,10000U,74,M,27
494 | 84,5,12,8,5,10000U,74,M,49
495 | 84,6,16,8,5,10000U,74,M,60
496 | 85,1,0,8,6,Placebo,41,M,37
497 | 86,1,0,8,7,10000U,65,F,24
498 | 86,2,2,8,7,10000U,65,F,29
499 | 86,3,4,8,7,10000U,65,F,18
500 | 86,4,8,8,7,10000U,65,F,20
501 | 86,5,12,8,7,10000U,65,F,25
502 | 86,6,16,8,7,10000U,65,F,41
503 | 87,1,0,8,8,5000U,79,M,42
504 | 87,2,2,8,8,5000U,79,M,23
505 | 87,3,4,8,8,5000U,79,M,30
506 | 87,4,8,8,8,5000U,79,M,36
507 | 87,5,12,8,8,5000U,79,M,41
508 | 87,6,16,8,8,5000U,79,M,43
509 | 88,1,0,8,9,Placebo,63,M,30
510 | 88,2,2,8,9,Placebo,63,M,22
511 | 88,3,4,8,9,Placebo,63,M,21
512 | 88,4,8,8,9,Placebo,63,M,25
513 | 88,5,12,8,9,Placebo,63,M,26
514 | 88,6,16,8,9,Placebo,63,M,33
515 | 89,1,0,8,10,Placebo,63,F,42
516 | 89,2,2,8,10,Placebo,63,F,46
517 | 89,3,4,8,10,Placebo,63,F,41
518 | 89,4,8,8,10,Placebo,63,F,43
519 | 89,5,12,8,10,Placebo,63,F,49
520 | 89,6,16,8,10,Placebo,63,F,54
521 | 90,1,0,8,11,10000U,34,F,49
522 | 90,2,2,8,11,10000U,34,F,25
523 | 90,3,4,8,11,10000U,34,F,30
524 | 90,4,8,8,11,10000U,34,F,49
525 | 90,5,12,8,11,10000U,34,F,55
526 | 90,6,16,8,11,10000U,34,F,58
527 | 91,1,0,8,12,5000U,42,M,58
528 | 91,2,2,8,12,5000U,42,M,46
529 | 91,3,4,8,12,5000U,42,M,46
530 | 91,4,8,8,12,5000U,42,M,50
531 | 91,5,12,8,12,5000U,42,M,56
532 | 91,6,16,8,12,5000U,42,M,60
533 | 92,1,0,8,13,Placebo,57,M,26
534 | 92,2,2,8,13,Placebo,57,M,26
535 | 92,3,4,8,13,Placebo,57,M,27
536 | 92,4,8,8,13,Placebo,57,M,22
537 | 92,5,12,8,13,Placebo,57,M,38
538 | 92,6,16,8,13,Placebo,57,M,35
539 | 93,1,0,8,14,5000U,68,M,37
540 | 93,3,4,8,14,5000U,68,M,23
541 | 93,4,8,8,14,5000U,68,M,18
542 | 93,5,12,8,14,5000U,68,M,34
543 | 93,6,16,8,14,5000U,68,M,36
544 | 94,1,0,8,15,10000U,51,M,40
545 | 94,2,2,8,15,10000U,51,M,24
546 | 94,3,4,8,15,10000U,51,M,25
547 | 94,4,8,8,15,10000U,51,M,37
548 | 94,6,16,8,15,10000U,51,M,38
549 | 95,1,0,8,16,5000U,51,F,33
550 | 95,2,2,8,16,5000U,51,F,10
551 | 95,3,4,8,16,5000U,51,F,13
552 | 95,4,8,8,16,5000U,51,F,16
553 | 95,5,12,8,16,5000U,51,F,32
554 | 95,6,16,8,16,5000U,51,F,16
555 | 96,1,0,8,17,10000U,61,F,41
556 | 96,2,2,8,17,10000U,61,F,50
557 | 96,3,4,8,17,10000U,61,F,22
558 | 96,4,8,8,17,10000U,61,F,28
559 | 96,5,12,8,17,10000U,61,F,34
560 | 96,6,16,8,17,10000U,61,F,36
561 | 97,1,0,8,18,Placebo,42,M,46
562 | 97,3,4,8,18,Placebo,42,M,41
563 | 97,4,8,8,18,Placebo,42,M,41
564 | 97,5,12,8,18,Placebo,42,M,58
565 | 97,6,16,8,18,Placebo,42,M,53
566 | 98,1,0,8,19,10000U,73,F,40
567 | 98,2,2,8,19,10000U,73,F,28
568 | 98,3,4,8,19,10000U,73,F,29
569 | 98,4,8,8,19,10000U,73,F,30
570 | 98,5,12,8,19,10000U,73,F,37
571 | 98,6,16,8,19,10000U,73,F,44
572 | 99,1,0,9,1,10000U,57,M,40
573 | 99,2,2,9,1,10000U,57,M,16
574 | 99,3,4,9,1,10000U,57,M,18
575 | 99,4,8,9,1,10000U,57,M,25
576 | 99,5,12,9,1,10000U,57,M,33
577 | 99,6,16,9,1,10000U,57,M,48
578 | 100,1,0,9,2,Placebo,59,M,61
579 | 100,2,2,9,2,Placebo,59,M,52
580 | 100,3,4,9,2,Placebo,59,M,61
581 | 100,4,8,9,2,Placebo,59,M,68
582 | 100,5,12,9,2,Placebo,59,M,59
583 | 100,6,16,9,2,Placebo,59,M,71
584 | 101,1,0,9,3,5000U,57,M,35
585 | 101,2,2,9,3,5000U,57,M,21
586 | 101,3,4,9,3,5000U,57,M,29
587 | 101,4,8,9,3,5000U,57,M,30
588 | 101,5,12,9,3,5000U,57,M,35
589 | 101,6,16,9,3,5000U,57,M,48
590 | 102,1,0,9,4,Placebo,68,F,58
591 | 102,2,2,9,4,Placebo,68,F,38
592 | 102,3,4,9,4,Placebo,68,F,50
593 | 102,4,8,9,4,Placebo,68,F,53
594 | 102,5,12,9,4,Placebo,68,F,47
595 | 102,6,16,9,4,Placebo,68,F,59
596 | 103,1,0,9,5,5000U,55,F,49
597 | 103,2,2,9,5,5000U,55,F,45
598 | 103,3,4,9,5,5000U,55,F,36
599 | 103,5,12,9,5,5000U,55,F,40
600 | 103,6,16,9,5,5000U,55,F,52
601 | 104,1,0,9,6,10000U,46,F,52
602 | 104,2,2,9,6,10000U,46,F,46
603 | 104,3,4,9,6,10000U,46,F,36
604 | 104,5,12,9,6,10000U,46,F,45
605 | 104,6,16,9,6,10000U,46,F,54
606 | 105,1,0,9,7,Placebo,79,F,45
607 | 105,2,2,9,7,Placebo,79,F,46
608 | 105,3,4,9,7,Placebo,79,F,33
609 | 105,4,8,9,7,Placebo,79,F,44
610 | 105,5,12,9,7,Placebo,79,F,46
611 | 105,6,16,9,7,Placebo,79,F,48
612 | 106,1,0,9,8,5000U,43,M,67
613 | 106,2,2,9,8,5000U,43,M,63
614 | 106,3,4,9,8,5000U,43,M,71
615 | 106,4,8,9,8,5000U,43,M,66
616 | 106,5,12,9,8,5000U,43,M,68
617 | 106,6,16,9,8,5000U,43,M,71
618 | 107,1,0,9,9,10000U,50,M,57
619 | 107,3,4,9,9,10000U,50,M,36
620 | 107,4,8,9,9,10000U,50,M,23
621 | 107,6,16,9,9,10000U,50,M,52
622 | 108,1,0,9,10,10000U,39,F,63
623 | 108,2,2,9,10,10000U,39,F,51
624 | 108,3,4,9,10,10000U,39,F,46
625 | 108,4,8,9,10,10000U,39,F,50
626 | 108,5,12,9,10,10000U,39,F,50
627 | 108,6,16,9,10,10000U,39,F,54
628 | 109,1,0,9,11,5000U,57,M,53
629 | 109,2,2,9,11,5000U,57,M,38
630 | 109,4,8,9,11,5000U,57,M,33
631 | 109,5,12,9,11,5000U,57,M,36
632 | 109,6,16,9,11,5000U,57,M,51
633 |
--------------------------------------------------------------------------------
/Lecture 4/data/cpi.csv:
--------------------------------------------------------------------------------
1 | DATE,CPIAUCSL
2 | 1947-01-01,21.48
3 | 1947-02-01,21.62
4 | 1947-03-01,22.0
5 | 1947-04-01,22.0
6 | 1947-05-01,21.95
7 | 1947-06-01,22.08
8 | 1947-07-01,22.23
9 | 1947-08-01,22.4
10 | 1947-09-01,22.84
11 | 1947-10-01,22.91
12 | 1947-11-01,23.06
13 | 1947-12-01,23.41
14 | 1948-01-01,23.68
15 | 1948-02-01,23.67
16 | 1948-03-01,23.5
17 | 1948-04-01,23.82
18 | 1948-05-01,24.01
19 | 1948-06-01,24.15
20 | 1948-07-01,24.4
21 | 1948-08-01,24.43
22 | 1948-09-01,24.36
23 | 1948-10-01,24.31
24 | 1948-11-01,24.16
25 | 1948-12-01,24.05
26 | 1949-01-01,24.01
27 | 1949-02-01,23.91
28 | 1949-03-01,23.91
29 | 1949-04-01,23.92
30 | 1949-05-01,23.91
31 | 1949-06-01,23.92
32 | 1949-07-01,23.7
33 | 1949-08-01,23.7
34 | 1949-09-01,23.75
35 | 1949-10-01,23.67
36 | 1949-11-01,23.7
37 | 1949-12-01,23.61
38 | 1950-01-01,23.51
39 | 1950-02-01,23.61
40 | 1950-03-01,23.64
41 | 1950-04-01,23.65
42 | 1950-05-01,23.77
43 | 1950-06-01,23.88
44 | 1950-07-01,24.07
45 | 1950-08-01,24.2
46 | 1950-09-01,24.34
47 | 1950-10-01,24.5
48 | 1950-11-01,24.6
49 | 1950-12-01,24.98
50 | 1951-01-01,25.38
51 | 1951-02-01,25.83
52 | 1951-03-01,25.88
53 | 1951-04-01,25.92
54 | 1951-05-01,25.99
55 | 1951-06-01,25.93
56 | 1951-07-01,25.91
57 | 1951-08-01,25.86
58 | 1951-09-01,26.03
59 | 1951-10-01,26.16
60 | 1951-11-01,26.32
61 | 1951-12-01,26.47
62 | 1952-01-01,26.45
63 | 1952-02-01,26.41
64 | 1952-03-01,26.39
65 | 1952-04-01,26.46
66 | 1952-05-01,26.47
67 | 1952-06-01,26.53
68 | 1952-07-01,26.68
69 | 1952-08-01,26.69
70 | 1952-09-01,26.63
71 | 1952-10-01,26.69
72 | 1952-11-01,26.69
73 | 1952-12-01,26.71
74 | 1953-01-01,26.64
75 | 1953-02-01,26.59
76 | 1953-03-01,26.63
77 | 1953-04-01,26.69
78 | 1953-05-01,26.7
79 | 1953-06-01,26.77
80 | 1953-07-01,26.79
81 | 1953-08-01,26.85
82 | 1953-09-01,26.89
83 | 1953-10-01,26.95
84 | 1953-11-01,26.85
85 | 1953-12-01,26.87
86 | 1954-01-01,26.94
87 | 1954-02-01,26.99
88 | 1954-03-01,26.93
89 | 1954-04-01,26.86
90 | 1954-05-01,26.93
91 | 1954-06-01,26.94
92 | 1954-07-01,26.86
93 | 1954-08-01,26.85
94 | 1954-09-01,26.81
95 | 1954-10-01,26.72
96 | 1954-11-01,26.78
97 | 1954-12-01,26.77
98 | 1955-01-01,26.77
99 | 1955-02-01,26.82
100 | 1955-03-01,26.79
101 | 1955-04-01,26.79
102 | 1955-05-01,26.77
103 | 1955-06-01,26.71
104 | 1955-07-01,26.76
105 | 1955-08-01,26.72
106 | 1955-09-01,26.85
107 | 1955-10-01,26.82
108 | 1955-11-01,26.88
109 | 1955-12-01,26.87
110 | 1956-01-01,26.83
111 | 1956-02-01,26.86
112 | 1956-03-01,26.89
113 | 1956-04-01,26.93
114 | 1956-05-01,27.03
115 | 1956-06-01,27.15
116 | 1956-07-01,27.29
117 | 1956-08-01,27.31
118 | 1956-09-01,27.35
119 | 1956-10-01,27.51
120 | 1956-11-01,27.51
121 | 1956-12-01,27.63
122 | 1957-01-01,27.67
123 | 1957-02-01,27.8
124 | 1957-03-01,27.86
125 | 1957-04-01,27.93
126 | 1957-05-01,28.0
127 | 1957-06-01,28.11
128 | 1957-07-01,28.19
129 | 1957-08-01,28.28
130 | 1957-09-01,28.32
131 | 1957-10-01,28.32
132 | 1957-11-01,28.41
133 | 1957-12-01,28.47
134 | 1958-01-01,28.64
135 | 1958-02-01,28.7
136 | 1958-03-01,28.87
137 | 1958-04-01,28.94
138 | 1958-05-01,28.94
139 | 1958-06-01,28.91
140 | 1958-07-01,28.89
141 | 1958-08-01,28.94
142 | 1958-09-01,28.91
143 | 1958-10-01,28.91
144 | 1958-11-01,28.95
145 | 1958-12-01,28.97
146 | 1959-01-01,29.01
147 | 1959-02-01,29.0
148 | 1959-03-01,28.97
149 | 1959-04-01,28.98
150 | 1959-05-01,29.04
151 | 1959-06-01,29.11
152 | 1959-07-01,29.15
153 | 1959-08-01,29.18
154 | 1959-09-01,29.25
155 | 1959-10-01,29.35
156 | 1959-11-01,29.35
157 | 1959-12-01,29.41
158 | 1960-01-01,29.37
159 | 1960-02-01,29.41
160 | 1960-03-01,29.41
161 | 1960-04-01,29.54
162 | 1960-05-01,29.57
163 | 1960-06-01,29.61
164 | 1960-07-01,29.55
165 | 1960-08-01,29.61
166 | 1960-09-01,29.61
167 | 1960-10-01,29.75
168 | 1960-11-01,29.78
169 | 1960-12-01,29.81
170 | 1961-01-01,29.84
171 | 1961-02-01,29.84
172 | 1961-03-01,29.84
173 | 1961-04-01,29.81
174 | 1961-05-01,29.84
175 | 1961-06-01,29.84
176 | 1961-07-01,29.92
177 | 1961-08-01,29.94
178 | 1961-09-01,29.98
179 | 1961-10-01,29.98
180 | 1961-11-01,29.98
181 | 1961-12-01,30.01
182 | 1962-01-01,30.04
183 | 1962-02-01,30.11
184 | 1962-03-01,30.17
185 | 1962-04-01,30.21
186 | 1962-05-01,30.24
187 | 1962-06-01,30.21
188 | 1962-07-01,30.22
189 | 1962-08-01,30.28
190 | 1962-09-01,30.42
191 | 1962-10-01,30.38
192 | 1962-11-01,30.38
193 | 1962-12-01,30.38
194 | 1963-01-01,30.44
195 | 1963-02-01,30.48
196 | 1963-03-01,30.51
197 | 1963-04-01,30.48
198 | 1963-05-01,30.51
199 | 1963-06-01,30.61
200 | 1963-07-01,30.69
201 | 1963-08-01,30.75
202 | 1963-09-01,30.72
203 | 1963-10-01,30.75
204 | 1963-11-01,30.78
205 | 1963-12-01,30.88
206 | 1964-01-01,30.94
207 | 1964-02-01,30.91
208 | 1964-03-01,30.94
209 | 1964-04-01,30.95
210 | 1964-05-01,30.98
211 | 1964-06-01,31.01
212 | 1964-07-01,31.02
213 | 1964-08-01,31.05
214 | 1964-09-01,31.08
215 | 1964-10-01,31.12
216 | 1964-11-01,31.21
217 | 1964-12-01,31.25
218 | 1965-01-01,31.28
219 | 1965-02-01,31.28
220 | 1965-03-01,31.31
221 | 1965-04-01,31.38
222 | 1965-05-01,31.48
223 | 1965-06-01,31.61
224 | 1965-07-01,31.58
225 | 1965-08-01,31.55
226 | 1965-09-01,31.62
227 | 1965-10-01,31.65
228 | 1965-11-01,31.75
229 | 1965-12-01,31.85
230 | 1966-01-01,31.88
231 | 1966-02-01,32.08
232 | 1966-03-01,32.18
233 | 1966-04-01,32.28
234 | 1966-05-01,32.35
235 | 1966-06-01,32.38
236 | 1966-07-01,32.45
237 | 1966-08-01,32.65
238 | 1966-09-01,32.75
239 | 1966-10-01,32.85
240 | 1966-11-01,32.88
241 | 1966-12-01,32.92
242 | 1967-01-01,32.9
243 | 1967-02-01,33.0
244 | 1967-03-01,33.0
245 | 1967-04-01,33.1
246 | 1967-05-01,33.1
247 | 1967-06-01,33.3
248 | 1967-07-01,33.4
249 | 1967-08-01,33.5
250 | 1967-09-01,33.6
251 | 1967-10-01,33.7
252 | 1967-11-01,33.9
253 | 1967-12-01,34.0
254 | 1968-01-01,34.1
255 | 1968-02-01,34.2
256 | 1968-03-01,34.3
257 | 1968-04-01,34.4
258 | 1968-05-01,34.5
259 | 1968-06-01,34.7
260 | 1968-07-01,34.9
261 | 1968-08-01,35.0
262 | 1968-09-01,35.1
263 | 1968-10-01,35.3
264 | 1968-11-01,35.4
265 | 1968-12-01,35.6
266 | 1969-01-01,35.7
267 | 1969-02-01,35.8
268 | 1969-03-01,36.1
269 | 1969-04-01,36.3
270 | 1969-05-01,36.4
271 | 1969-06-01,36.6
272 | 1969-07-01,36.8
273 | 1969-08-01,36.9
274 | 1969-09-01,37.1
275 | 1969-10-01,37.3
276 | 1969-11-01,37.5
277 | 1969-12-01,37.7
278 | 1970-01-01,37.9
279 | 1970-02-01,38.1
280 | 1970-03-01,38.3
281 | 1970-04-01,38.5
282 | 1970-05-01,38.6
283 | 1970-06-01,38.8
284 | 1970-07-01,38.9
285 | 1970-08-01,39.0
286 | 1970-09-01,39.2
287 | 1970-10-01,39.4
288 | 1970-11-01,39.6
289 | 1970-12-01,39.8
290 | 1971-01-01,39.9
291 | 1971-02-01,39.9
292 | 1971-03-01,40.0
293 | 1971-04-01,40.1
294 | 1971-05-01,40.3
295 | 1971-06-01,40.5
296 | 1971-07-01,40.6
297 | 1971-08-01,40.7
298 | 1971-09-01,40.8
299 | 1971-10-01,40.9
300 | 1971-11-01,41.0
301 | 1971-12-01,41.1
302 | 1972-01-01,41.2
303 | 1972-02-01,41.4
304 | 1972-03-01,41.4
305 | 1972-04-01,41.5
306 | 1972-05-01,41.6
307 | 1972-06-01,41.7
308 | 1972-07-01,41.8
309 | 1972-08-01,41.9
310 | 1972-09-01,42.1
311 | 1972-10-01,42.2
312 | 1972-11-01,42.4
313 | 1972-12-01,42.5
314 | 1973-01-01,42.7
315 | 1973-02-01,43.0
316 | 1973-03-01,43.4
317 | 1973-04-01,43.7
318 | 1973-05-01,43.9
319 | 1973-06-01,44.2
320 | 1973-07-01,44.2
321 | 1973-08-01,45.0
322 | 1973-09-01,45.2
323 | 1973-10-01,45.6
324 | 1973-11-01,45.9
325 | 1973-12-01,46.3
326 | 1974-01-01,46.8
327 | 1974-02-01,47.3
328 | 1974-03-01,47.8
329 | 1974-04-01,48.1
330 | 1974-05-01,48.6
331 | 1974-06-01,49.0
332 | 1974-07-01,49.3
333 | 1974-08-01,49.9
334 | 1974-09-01,50.6
335 | 1974-10-01,51.0
336 | 1974-11-01,51.5
337 | 1974-12-01,51.9
338 | 1975-01-01,52.3
339 | 1975-02-01,52.6
340 | 1975-03-01,52.8
341 | 1975-04-01,53.0
342 | 1975-05-01,53.1
343 | 1975-06-01,53.5
344 | 1975-07-01,54.0
345 | 1975-08-01,54.2
346 | 1975-09-01,54.6
347 | 1975-10-01,54.9
348 | 1975-11-01,55.3
349 | 1975-12-01,55.6
350 | 1976-01-01,55.8
351 | 1976-02-01,55.9
352 | 1976-03-01,56.0
353 | 1976-04-01,56.1
354 | 1976-05-01,56.4
355 | 1976-06-01,56.7
356 | 1976-07-01,57.0
357 | 1976-08-01,57.3
358 | 1976-09-01,57.6
359 | 1976-10-01,57.9
360 | 1976-11-01,58.1
361 | 1976-12-01,58.4
362 | 1977-01-01,58.7
363 | 1977-02-01,59.3
364 | 1977-03-01,59.6
365 | 1977-04-01,60.0
366 | 1977-05-01,60.2
367 | 1977-06-01,60.5
368 | 1977-07-01,60.8
369 | 1977-08-01,61.1
370 | 1977-09-01,61.3
371 | 1977-10-01,61.6
372 | 1977-11-01,62.0
373 | 1977-12-01,62.3
374 | 1978-01-01,62.7
375 | 1978-02-01,63.0
376 | 1978-03-01,63.4
377 | 1978-04-01,63.9
378 | 1978-05-01,64.5
379 | 1978-06-01,65.0
380 | 1978-07-01,65.5
381 | 1978-08-01,65.9
382 | 1978-09-01,66.5
383 | 1978-10-01,67.1
384 | 1978-11-01,67.5
385 | 1978-12-01,67.9
386 | 1979-01-01,68.5
387 | 1979-02-01,69.2
388 | 1979-03-01,69.9
389 | 1979-04-01,70.6
390 | 1979-05-01,71.4
391 | 1979-06-01,72.2
392 | 1979-07-01,73.0
393 | 1979-08-01,73.7
394 | 1979-09-01,74.4
395 | 1979-10-01,75.2
396 | 1979-11-01,76.0
397 | 1979-12-01,76.9
398 | 1980-01-01,78.0
399 | 1980-02-01,79.0
400 | 1980-03-01,80.1
401 | 1980-04-01,80.9
402 | 1980-05-01,81.7
403 | 1980-06-01,82.5
404 | 1980-07-01,82.6
405 | 1980-08-01,83.2
406 | 1980-09-01,83.9
407 | 1980-10-01,84.7
408 | 1980-11-01,85.6
409 | 1980-12-01,86.4
410 | 1981-01-01,87.2
411 | 1981-02-01,88.0
412 | 1981-03-01,88.6
413 | 1981-04-01,89.1
414 | 1981-05-01,89.7
415 | 1981-06-01,90.5
416 | 1981-07-01,91.5
417 | 1981-08-01,92.2
418 | 1981-09-01,93.1
419 | 1981-10-01,93.4
420 | 1981-11-01,93.8
421 | 1981-12-01,94.1
422 | 1982-01-01,94.4
423 | 1982-02-01,94.7
424 | 1982-03-01,94.7
425 | 1982-04-01,95.0
426 | 1982-05-01,95.9
427 | 1982-06-01,97.0
428 | 1982-07-01,97.5
429 | 1982-08-01,97.7
430 | 1982-09-01,97.7
431 | 1982-10-01,98.1
432 | 1982-11-01,98.0
433 | 1982-12-01,97.7
434 | 1983-01-01,97.9
435 | 1983-02-01,98.0
436 | 1983-03-01,98.1
437 | 1983-04-01,98.8
438 | 1983-05-01,99.2
439 | 1983-06-01,99.4
440 | 1983-07-01,99.8
441 | 1983-08-01,100.1
442 | 1983-09-01,100.4
443 | 1983-10-01,100.8
444 | 1983-11-01,101.1
445 | 1983-12-01,101.4
446 | 1984-01-01,102.1
447 | 1984-02-01,102.6
448 | 1984-03-01,102.9
449 | 1984-04-01,103.3
450 | 1984-05-01,103.5
451 | 1984-06-01,103.7
452 | 1984-07-01,104.1
453 | 1984-08-01,104.4
454 | 1984-09-01,104.7
455 | 1984-10-01,105.1
456 | 1984-11-01,105.3
457 | 1984-12-01,105.5
458 | 1985-01-01,105.7
459 | 1985-02-01,106.3
460 | 1985-03-01,106.8
461 | 1985-04-01,107.0
462 | 1985-05-01,107.2
463 | 1985-06-01,107.5
464 | 1985-07-01,107.7
465 | 1985-08-01,107.9
466 | 1985-09-01,108.1
467 | 1985-10-01,108.5
468 | 1985-11-01,109.0
469 | 1985-12-01,109.5
470 | 1986-01-01,109.9
471 | 1986-02-01,109.7
472 | 1986-03-01,109.1
473 | 1986-04-01,108.7
474 | 1986-05-01,109.0
475 | 1986-06-01,109.4
476 | 1986-07-01,109.5
477 | 1986-08-01,109.6
478 | 1986-09-01,110.0
479 | 1986-10-01,110.2
480 | 1986-11-01,110.4
481 | 1986-12-01,110.8
482 | 1987-01-01,111.4
483 | 1987-02-01,111.8
484 | 1987-03-01,112.2
485 | 1987-04-01,112.7
486 | 1987-05-01,113.0
487 | 1987-06-01,113.5
488 | 1987-07-01,113.8
489 | 1987-08-01,114.3
490 | 1987-09-01,114.7
491 | 1987-10-01,115.0
492 | 1987-11-01,115.4
493 | 1987-12-01,115.6
494 | 1988-01-01,116.0
495 | 1988-02-01,116.2
496 | 1988-03-01,116.5
497 | 1988-04-01,117.2
498 | 1988-05-01,117.5
499 | 1988-06-01,118.0
500 | 1988-07-01,118.5
501 | 1988-08-01,119.0
502 | 1988-09-01,119.5
503 | 1988-10-01,119.9
504 | 1988-11-01,120.3
505 | 1988-12-01,120.7
506 | 1989-01-01,121.2
507 | 1989-02-01,121.6
508 | 1989-03-01,122.2
509 | 1989-04-01,123.1
510 | 1989-05-01,123.7
511 | 1989-06-01,124.1
512 | 1989-07-01,124.5
513 | 1989-08-01,124.5
514 | 1989-09-01,124.8
515 | 1989-10-01,125.4
516 | 1989-11-01,125.9
517 | 1989-12-01,126.3
518 | 1990-01-01,127.5
519 | 1990-02-01,128.0
520 | 1990-03-01,128.6
521 | 1990-04-01,128.9
522 | 1990-05-01,129.1
523 | 1990-06-01,129.9
524 | 1990-07-01,130.5
525 | 1990-08-01,131.6
526 | 1990-09-01,132.5
527 | 1990-10-01,133.4
528 | 1990-11-01,133.7
529 | 1990-12-01,134.2
530 | 1991-01-01,134.7
531 | 1991-02-01,134.8
532 | 1991-03-01,134.8
533 | 1991-04-01,135.1
534 | 1991-05-01,135.6
535 | 1991-06-01,136.0
536 | 1991-07-01,136.2
537 | 1991-08-01,136.6
538 | 1991-09-01,137.0
539 | 1991-10-01,137.2
540 | 1991-11-01,137.8
541 | 1991-12-01,138.2
542 | 1992-01-01,138.3
543 | 1992-02-01,138.6
544 | 1992-03-01,139.1
545 | 1992-04-01,139.4
546 | 1992-05-01,139.7
547 | 1992-06-01,140.1
548 | 1992-07-01,140.5
549 | 1992-08-01,140.8
550 | 1992-09-01,141.1
551 | 1992-10-01,141.7
552 | 1992-11-01,142.1
553 | 1992-12-01,142.3
554 | 1993-01-01,142.8
555 | 1993-02-01,143.1
556 | 1993-03-01,143.3
557 | 1993-04-01,143.8
558 | 1993-05-01,144.2
559 | 1993-06-01,144.3
560 | 1993-07-01,144.5
561 | 1993-08-01,144.8
562 | 1993-09-01,145.0
563 | 1993-10-01,145.6
564 | 1993-11-01,146.0
565 | 1993-12-01,146.3
566 | 1994-01-01,146.3
567 | 1994-02-01,146.7
568 | 1994-03-01,147.1
569 | 1994-04-01,147.2
570 | 1994-05-01,147.5
571 | 1994-06-01,147.9
572 | 1994-07-01,148.4
573 | 1994-08-01,149.0
574 | 1994-09-01,149.3
575 | 1994-10-01,149.4
576 | 1994-11-01,149.8
577 | 1994-12-01,150.1
578 | 1995-01-01,150.5
579 | 1995-02-01,150.9
580 | 1995-03-01,151.2
581 | 1995-04-01,151.8
582 | 1995-05-01,152.1
583 | 1995-06-01,152.4
584 | 1995-07-01,152.6
585 | 1995-08-01,152.9
586 | 1995-09-01,153.1
587 | 1995-10-01,153.5
588 | 1995-11-01,153.7
589 | 1995-12-01,153.9
590 | 1996-01-01,154.7
591 | 1996-02-01,155.0
592 | 1996-03-01,155.5
593 | 1996-04-01,156.1
594 | 1996-05-01,156.4
595 | 1996-06-01,156.7
596 | 1996-07-01,157.0
597 | 1996-08-01,157.2
598 | 1996-09-01,157.7
599 | 1996-10-01,158.2
600 | 1996-11-01,158.7
601 | 1996-12-01,159.1
602 | 1997-01-01,159.4
603 | 1997-02-01,159.7
604 | 1997-03-01,159.8
605 | 1997-04-01,159.9
606 | 1997-05-01,159.9
607 | 1997-06-01,160.2
608 | 1997-07-01,160.4
609 | 1997-08-01,160.8
610 | 1997-09-01,161.2
611 | 1997-10-01,161.5
612 | 1997-11-01,161.7
613 | 1997-12-01,161.8
614 | 1998-01-01,162.0
615 | 1998-02-01,162.0
616 | 1998-03-01,162.0
617 | 1998-04-01,162.2
618 | 1998-05-01,162.6
619 | 1998-06-01,162.8
620 | 1998-07-01,163.2
621 | 1998-08-01,163.4
622 | 1998-09-01,163.5
623 | 1998-10-01,163.9
624 | 1998-11-01,164.1
625 | 1998-12-01,164.4
626 | 1999-01-01,164.7
627 | 1999-02-01,164.7
628 | 1999-03-01,164.8
629 | 1999-04-01,165.9
630 | 1999-05-01,166.0
631 | 1999-06-01,166.0
632 | 1999-07-01,166.7
633 | 1999-08-01,167.1
634 | 1999-09-01,167.8
635 | 1999-10-01,168.1
636 | 1999-11-01,168.4
637 | 1999-12-01,168.8
638 | 2000-01-01,169.3
639 | 2000-02-01,170.0
640 | 2000-03-01,171.0
641 | 2000-04-01,170.9
642 | 2000-05-01,171.2
643 | 2000-06-01,172.2
644 | 2000-07-01,172.7
645 | 2000-08-01,172.7
646 | 2000-09-01,173.6
647 | 2000-10-01,173.9
648 | 2000-11-01,174.2
649 | 2000-12-01,174.6
650 | 2001-01-01,175.6
651 | 2001-02-01,176.0
652 | 2001-03-01,176.1
653 | 2001-04-01,176.4
654 | 2001-05-01,177.3
655 | 2001-06-01,177.7
656 | 2001-07-01,177.4
657 | 2001-08-01,177.4
658 | 2001-09-01,178.1
659 | 2001-10-01,177.6
660 | 2001-11-01,177.5
661 | 2001-12-01,177.4
662 | 2002-01-01,177.7
663 | 2002-02-01,178.0
664 | 2002-03-01,178.5
665 | 2002-04-01,179.3
666 | 2002-05-01,179.5
667 | 2002-06-01,179.6
668 | 2002-07-01,180.0
669 | 2002-08-01,180.5
670 | 2002-09-01,180.8
671 | 2002-10-01,181.2
672 | 2002-11-01,181.5
673 | 2002-12-01,181.8
674 | 2003-01-01,182.6
675 | 2003-02-01,183.6
676 | 2003-03-01,183.9
677 | 2003-04-01,183.2
678 | 2003-05-01,182.9
679 | 2003-06-01,183.1
680 | 2003-07-01,183.7
681 | 2003-08-01,184.5
682 | 2003-09-01,185.1
683 | 2003-10-01,184.9
684 | 2003-11-01,185.0
685 | 2003-12-01,185.5
686 | 2004-01-01,186.3
687 | 2004-02-01,186.7
688 | 2004-03-01,187.1
689 | 2004-04-01,187.4
690 | 2004-05-01,188.2
691 | 2004-06-01,188.9
692 | 2004-07-01,189.1
693 | 2004-08-01,189.2
694 | 2004-09-01,189.8
695 | 2004-10-01,190.8
696 | 2004-11-01,191.7
697 | 2004-12-01,191.7
698 | 2005-01-01,191.6
699 | 2005-02-01,192.4
700 | 2005-03-01,193.1
701 | 2005-04-01,193.7
702 | 2005-05-01,193.6
703 | 2005-06-01,193.7
704 | 2005-07-01,194.9
705 | 2005-08-01,196.1
706 | 2005-09-01,198.8
707 | 2005-10-01,199.1
708 | 2005-11-01,198.1
709 | 2005-12-01,198.1
710 | 2006-01-01,199.3
711 | 2006-02-01,199.4
712 | 2006-03-01,199.7
713 | 2006-04-01,200.7
714 | 2006-05-01,201.3
715 | 2006-06-01,201.8
716 | 2006-07-01,202.9
717 | 2006-08-01,203.8
718 | 2006-09-01,202.8
719 | 2006-10-01,201.9
720 | 2006-11-01,202.0
721 | 2006-12-01,203.1
722 | 2007-01-01,203.437
723 | 2007-02-01,204.226
724 | 2007-03-01,205.28799999999998
725 | 2007-04-01,205.90400000000002
726 | 2007-05-01,206.755
727 | 2007-06-01,207.234
728 | 2007-07-01,207.60299999999998
729 | 2007-08-01,207.667
730 | 2007-09-01,208.547
731 | 2007-10-01,209.19
732 | 2007-11-01,210.834
733 | 2007-12-01,211.445
734 | 2008-01-01,212.174
735 | 2008-02-01,212.687
736 | 2008-03-01,213.44799999999998
737 | 2008-04-01,213.942
738 | 2008-05-01,215.208
739 | 2008-06-01,217.463
740 | 2008-07-01,219.016
741 | 2008-08-01,218.69
742 | 2008-09-01,218.877
743 | 2008-10-01,216.995
744 | 2008-11-01,213.153
745 | 2008-12-01,211.398
746 | 2009-01-01,211.933
747 | 2009-02-01,212.705
748 | 2009-03-01,212.495
749 | 2009-04-01,212.709
750 | 2009-05-01,213.02200000000002
751 | 2009-06-01,214.79
752 | 2009-07-01,214.726
753 | 2009-08-01,215.445
754 | 2009-09-01,215.861
755 | 2009-10-01,216.50900000000001
756 | 2009-11-01,217.234
757 | 2009-12-01,217.347
758 | 2010-01-01,217.488
759 | 2010-02-01,217.28099999999998
760 | 2010-03-01,217.35299999999998
761 | 2010-04-01,217.403
762 | 2010-05-01,217.29
763 | 2010-06-01,217.199
764 | 2010-07-01,217.605
765 | 2010-08-01,217.923
766 | 2010-09-01,218.275
767 | 2010-10-01,219.035
768 | 2010-11-01,219.59
769 | 2010-12-01,220.472
770 | 2011-01-01,221.187
771 | 2011-02-01,221.898
772 | 2011-03-01,223.046
773 | 2011-04-01,224.093
774 | 2011-05-01,224.80599999999998
775 | 2011-06-01,224.80599999999998
776 | 2011-07-01,225.395
777 | 2011-08-01,226.106
778 | 2011-09-01,226.597
779 | 2011-10-01,226.75
780 | 2011-11-01,227.169
781 | 2011-12-01,227.22299999999998
782 | 2012-01-01,227.86
783 | 2012-02-01,228.377
784 | 2012-03-01,228.894
785 | 2012-04-01,229.28599999999997
786 | 2012-05-01,228.722
787 | 2012-06-01,228.50599999999997
788 | 2012-07-01,228.475
789 | 2012-08-01,229.84400000000002
790 | 2012-09-01,230.987
791 | 2012-10-01,231.655
792 | 2012-11-01,231.278
793 | 2012-12-01,231.27200000000002
794 | 2013-01-01,231.641
795 | 2013-02-01,233.005
796 | 2013-03-01,232.313
797 | 2013-04-01,231.856
798 | 2013-05-01,231.895
799 | 2013-06-01,232.357
800 | 2013-07-01,232.74900000000002
801 | 2013-08-01,233.24900000000002
802 | 2013-09-01,233.642
803 | 2013-10-01,233.799
804 | 2013-11-01,234.21
805 | 2013-12-01,234.847
806 | 2014-01-01,235.43599999999998
807 | 2014-02-01,235.62099999999998
808 | 2014-03-01,235.89700000000002
809 | 2014-04-01,236.495
810 | 2014-05-01,236.803
811 | 2014-06-01,237.016
812 | 2014-07-01,237.25900000000001
813 | 2014-08-01,237.16299999999998
814 | 2014-09-01,237.51
815 | 2014-10-01,237.65099999999998
816 | 2014-11-01,237.261
817 | 2014-12-01,236.46400000000003
818 | 2015-01-01,234.954
819 | 2015-02-01,235.415
820 | 2015-03-01,235.859
821 | 2015-04-01,236.197
822 | 2015-05-01,236.87599999999998
823 |
--------------------------------------------------------------------------------
/Lecture 4/data/gdp.csv:
--------------------------------------------------------------------------------
1 | DATE,GDP
2 | 1947-01-01,243.1
3 | 1947-04-01,246.3
4 | 1947-07-01,250.1
5 | 1947-10-01,260.3
6 | 1948-01-01,266.2
7 | 1948-04-01,272.9
8 | 1948-07-01,279.5
9 | 1948-10-01,280.7
10 | 1949-01-01,275.4
11 | 1949-04-01,271.7
12 | 1949-07-01,273.3
13 | 1949-10-01,271.0
14 | 1950-01-01,281.2
15 | 1950-04-01,290.7
16 | 1950-07-01,308.5
17 | 1950-10-01,320.3
18 | 1951-01-01,336.4
19 | 1951-04-01,344.5
20 | 1951-07-01,351.8
21 | 1951-10-01,356.6
22 | 1952-01-01,360.2
23 | 1952-04-01,361.4
24 | 1952-07-01,368.1
25 | 1952-10-01,381.2
26 | 1953-01-01,388.5
27 | 1953-04-01,392.3
28 | 1953-07-01,391.7
29 | 1953-10-01,386.5
30 | 1954-01-01,385.9
31 | 1954-04-01,386.7
32 | 1954-07-01,391.6
33 | 1954-10-01,400.3
34 | 1955-01-01,413.8
35 | 1955-04-01,422.2
36 | 1955-07-01,430.9
37 | 1955-10-01,437.8
38 | 1956-01-01,440.5
39 | 1956-04-01,446.8
40 | 1956-07-01,452.0
41 | 1956-10-01,461.3
42 | 1957-01-01,470.6
43 | 1957-04-01,472.8
44 | 1957-07-01,480.3
45 | 1957-10-01,475.7
46 | 1958-01-01,468.4
47 | 1958-04-01,472.8
48 | 1958-07-01,486.7
49 | 1958-10-01,500.4
50 | 1959-01-01,511.1
51 | 1959-04-01,524.2
52 | 1959-07-01,525.2
53 | 1959-10-01,529.3
54 | 1960-01-01,543.3
55 | 1960-04-01,542.7
56 | 1960-07-01,546.0
57 | 1960-10-01,541.1
58 | 1961-01-01,545.9
59 | 1961-04-01,557.4
60 | 1961-07-01,568.2
61 | 1961-10-01,581.6
62 | 1962-01-01,595.2
63 | 1962-04-01,602.6
64 | 1962-07-01,609.6
65 | 1962-10-01,613.1
66 | 1963-01-01,622.7
67 | 1963-04-01,631.8
68 | 1963-07-01,645.0
69 | 1963-10-01,654.8
70 | 1964-01-01,671.1
71 | 1964-04-01,680.8
72 | 1964-07-01,692.8
73 | 1964-10-01,698.4
74 | 1965-01-01,719.2
75 | 1965-04-01,732.4
76 | 1965-07-01,750.2
77 | 1965-10-01,773.1
78 | 1966-01-01,797.3
79 | 1966-04-01,807.2
80 | 1966-07-01,820.8
81 | 1966-10-01,834.9
82 | 1967-01-01,846.0
83 | 1967-04-01,851.1
84 | 1967-07-01,866.6
85 | 1967-10-01,883.2
86 | 1968-01-01,911.1
87 | 1968-04-01,936.3
88 | 1968-07-01,952.3
89 | 1968-10-01,970.1
90 | 1969-01-01,995.4
91 | 1969-04-01,1011.4
92 | 1969-07-01,1032.0
93 | 1969-10-01,1040.7
94 | 1970-01-01,1053.5
95 | 1970-04-01,1070.1
96 | 1970-07-01,1088.5
97 | 1970-10-01,1091.5
98 | 1971-01-01,1137.8
99 | 1971-04-01,1159.4
100 | 1971-07-01,1180.3
101 | 1971-10-01,1193.6
102 | 1972-01-01,1233.8
103 | 1972-04-01,1270.1
104 | 1972-07-01,1293.8
105 | 1972-10-01,1332.0
106 | 1973-01-01,1380.7
107 | 1973-04-01,1417.6
108 | 1973-07-01,1436.8
109 | 1973-10-01,1479.1
110 | 1974-01-01,1494.7
111 | 1974-04-01,1534.2
112 | 1974-07-01,1563.4
113 | 1974-10-01,1603.0
114 | 1975-01-01,1619.6
115 | 1975-04-01,1656.4
116 | 1975-07-01,1713.8
117 | 1975-10-01,1765.9
118 | 1976-01-01,1824.5
119 | 1976-04-01,1856.9
120 | 1976-07-01,1890.5
121 | 1976-10-01,1938.4
122 | 1977-01-01,1992.5
123 | 1977-04-01,2060.2
124 | 1977-07-01,2122.4
125 | 1977-10-01,2168.7
126 | 1978-01-01,2208.7
127 | 1978-04-01,2336.6
128 | 1978-07-01,2398.9
129 | 1978-10-01,2482.2
130 | 1979-01-01,2531.6
131 | 1979-04-01,2595.9
132 | 1979-07-01,2670.4
133 | 1979-10-01,2730.7
134 | 1980-01-01,2796.5
135 | 1980-04-01,2799.9
136 | 1980-07-01,2860.0
137 | 1980-10-01,2993.5
138 | 1981-01-01,3131.8
139 | 1981-04-01,3167.3
140 | 1981-07-01,3261.2
141 | 1981-10-01,3283.5
142 | 1982-01-01,3273.8
143 | 1982-04-01,3331.3
144 | 1982-07-01,3367.1
145 | 1982-10-01,3407.8
146 | 1983-01-01,3480.3
147 | 1983-04-01,3583.8
148 | 1983-07-01,3692.3
149 | 1983-10-01,3796.1
150 | 1984-01-01,3912.8
151 | 1984-04-01,4015.0
152 | 1984-07-01,4087.4
153 | 1984-10-01,4147.6
154 | 1985-01-01,4237.0
155 | 1985-04-01,4302.3
156 | 1985-07-01,4394.6
157 | 1985-10-01,4453.1
158 | 1986-01-01,4516.3
159 | 1986-04-01,4555.2
160 | 1986-07-01,4619.6
161 | 1986-10-01,4669.4
162 | 1987-01-01,4736.2
163 | 1987-04-01,4821.5
164 | 1987-07-01,4900.5
165 | 1987-10-01,5022.7
166 | 1988-01-01,5090.6
167 | 1988-04-01,5207.7
168 | 1988-07-01,5299.5
169 | 1988-10-01,5412.7
170 | 1989-01-01,5527.4
171 | 1989-04-01,5628.4
172 | 1989-07-01,5711.6
173 | 1989-10-01,5763.4
174 | 1990-01-01,5890.8
175 | 1990-04-01,5974.7
176 | 1990-07-01,6029.5
177 | 1990-10-01,6023.3
178 | 1991-01-01,6054.9
179 | 1991-04-01,6143.6
180 | 1991-07-01,6218.4
181 | 1991-10-01,6279.3
182 | 1992-01-01,6380.8
183 | 1992-04-01,6492.3
184 | 1992-07-01,6586.5
185 | 1992-10-01,6697.6
186 | 1993-01-01,6748.2
187 | 1993-04-01,6829.6
188 | 1993-07-01,6904.2
189 | 1993-10-01,7032.8
190 | 1994-01-01,7136.3
191 | 1994-04-01,7269.8
192 | 1994-07-01,7352.3
193 | 1994-10-01,7476.7
194 | 1995-01-01,7545.3
195 | 1995-04-01,7604.9
196 | 1995-07-01,7706.5
197 | 1995-10-01,7799.5
198 | 1996-01-01,7893.1
199 | 1996-04-01,8061.5
200 | 1996-07-01,8159.0
201 | 1996-10-01,8287.1
202 | 1997-01-01,8402.1
203 | 1997-04-01,8551.9
204 | 1997-07-01,8691.8
205 | 1997-10-01,8788.3
206 | 1998-01-01,8889.7
207 | 1998-04-01,8994.7
208 | 1998-07-01,9146.5
209 | 1998-10-01,9325.7
210 | 1999-01-01,9447.1
211 | 1999-04-01,9557.0
212 | 1999-07-01,9712.3
213 | 1999-10-01,9926.1
214 | 2000-01-01,10031.0
215 | 2000-04-01,10278.3
216 | 2000-07-01,10357.4
217 | 2000-10-01,10472.3
218 | 2001-01-01,10508.1
219 | 2001-04-01,10638.4
220 | 2001-07-01,10639.5
221 | 2001-10-01,10701.3
222 | 2002-01-01,10834.4
223 | 2002-04-01,10934.8
224 | 2002-07-01,11037.1
225 | 2002-10-01,11103.8
226 | 2003-01-01,11230.1
227 | 2003-04-01,11370.7
228 | 2003-07-01,11625.1
229 | 2003-10-01,11816.8
230 | 2004-01-01,11988.4
231 | 2004-04-01,12181.4
232 | 2004-07-01,12367.7
233 | 2004-10-01,12562.2
234 | 2005-01-01,12813.7
235 | 2005-04-01,12974.1
236 | 2005-07-01,13205.4
237 | 2005-10-01,13381.6
238 | 2006-01-01,13648.9
239 | 2006-04-01,13799.8
240 | 2006-07-01,13908.5
241 | 2006-10-01,14066.4
242 | 2007-01-01,14233.2
243 | 2007-04-01,14422.3
244 | 2007-07-01,14569.7
245 | 2007-10-01,14685.3
246 | 2008-01-01,14668.4
247 | 2008-04-01,14813.0
248 | 2008-07-01,14843.0
249 | 2008-10-01,14549.9
250 | 2009-01-01,14383.9
251 | 2009-04-01,14340.4
252 | 2009-07-01,14384.1
253 | 2009-10-01,14566.5
254 | 2010-01-01,14681.1
255 | 2010-04-01,14888.6
256 | 2010-07-01,15057.7
257 | 2010-10-01,15230.2
258 | 2011-01-01,15238.4
259 | 2011-04-01,15460.9
260 | 2011-07-01,15587.1
261 | 2011-10-01,15785.3
262 | 2012-01-01,15973.9
263 | 2012-04-01,16121.9
264 | 2012-07-01,16227.9
265 | 2012-10-01,16297.3
266 | 2013-01-01,16475.4
267 | 2013-04-01,16541.4
268 | 2013-07-01,16749.3
269 | 2013-10-01,16999.9
270 | 2014-01-01,17025.2
271 |
--------------------------------------------------------------------------------
/Lecture 5/data/beer_subset.csv.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 5/data/beer_subset.csv.gz
--------------------------------------------------------------------------------
/Lecture 6/data/beer_subset.csv.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 6/data/beer_subset.csv.gz
--------------------------------------------------------------------------------
/Lecture 6/data/titanic.xls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ihmeuw/ihme-python-course/d1db20e910d19c07da2acf80632e1a4de8f12229/Lecture 6/data/titanic.xls
--------------------------------------------------------------------------------
/README.rst:
--------------------------------------------------------------------------------
1 | Intro
2 | =====
3 |
4 | Schedule
5 | --------
6 |
7 | +--------------+--------------+----------------------+----------------------------------------------+
8 | | Date | Session | Title | Description |
9 | +==============+==============+======================+==============================================+
10 | | Day 1 | Lecture 1 | Intro and Setup | *Why Python, Setup, etc* |
11 | +--------------+--------------+----------------------+----------------------------------------------+
12 | | Day 1 | Lecture 2 | Basic Python | *Syntax, data structures, control flow, etc* |
13 | +--------------+--------------+----------------------+----------------------------------------------+
14 | | Day 2 | Lecture 3 | Numpy + Pandas I | *Numpy basics, series + dataframe basics* |
15 | +--------------+--------------+----------------------+----------------------------------------------+
16 | | Day 2 | Lecture 4 | Pandas II | *Joining, advanced indexing, reshaping, etc* |
17 | +--------------+--------------+----------------------+----------------------------------------------+
18 | | Day 3 | Lecture 5 | Pandas III | *Grouping, apply, transform, etc* |
19 | +--------------+--------------+----------------------+----------------------------------------------+
20 | | Day 3 | Lecture 6 | Plotting | *Intro to plotting in Python* |
21 | +--------------+--------------+----------------------+----------------------------------------------+
22 | | Day 3 | Lecture 7 | Regression Intro | *Intro to regressions with Statsmodels* |
23 | +--------------+--------------+----------------------+----------------------------------------------+
24 |
25 |
26 | Getting started
27 | ===============
28 |
29 | Clone this repo
30 | ---------------
31 |
32 | First, you're going to want to get a copy of this repository onto your
33 | machine. Simply fire up ``git`` and clone it:
34 |
35 | 1. Open up a shell (e.g. ``cmd.exe`` or ``terminal.app``).
36 |
37 | 2. Navigate to where you'd like to save this. We recommend ``~/repos/``
38 | (e.g. ``C:/Users//repos/`` on Windows, ``/Users//repos/``
39 | on Mac, or ``/home//repos/`` on Unix).
40 |
41 | 3. Clone this repo:
42 |
43 | ::
44 |
45 | git clone https://github.com/ihmeuw/ihme-python-course.git
46 |
47 | Saving local changes
48 | --------------------
49 |
50 | You probably want to take notes, etc in your notebooks, so it's best to either
51 | fork this repo or just make a local branch to work off of:
52 |
53 | 1. Use `git checkout` to make a new branch
54 |
55 | ::
56 |
57 | git checkout -b my_branch_name
58 |
59 | 2. Save any changes using `git add` and then `git commit`
60 |
61 | ::
62 |
63 | git add .
64 | git commit -m "describe your change"
65 |
66 | 3. To get updates from the master branch, first fetch them:
67 |
68 | ::
69 |
70 | git fetch
71 |
72 | 4. Then apply the changes from master to your personal branch:
73 |
74 | ::
75 |
76 | git merge origin/master
77 |
78 |
79 |
80 | Installing Anaconda
81 | -------------------
82 |
83 | The easy way
84 | ~~~~~~~~~~~~
85 | Go to the `Anaconda download page `_ and
86 | download the installer for Python 3.5 (64-bit) and simply click through to
87 | follow the instructions
88 |
89 | The fancy way
90 | ~~~~~~~~~~~~~
91 | If you'd like to setup a
92 | `Docker container with Anaconda `_
93 | check out the `Docker setup instructions <./Docker-Instructions.rst>`_.
94 | But be warned that it doesn't play terribly nicely with Windows 7 or 8...
95 |
96 | Additional modules
97 | ~~~~~~~~~~~~~~~~~~
98 |
99 | - `seaborn `_
100 |
101 | ::
102 |
103 | conda install -c conda-forge seaborn
104 |
105 | - `ggplot `_
106 |
107 | ::
108 |
109 | conda install -c bokeh ggplot
110 |
111 | - `bokeh `_
112 |
113 | ::
114 |
115 | conda install -c bokeh bokeh
116 |
117 | - `statsmodels `_
118 |
119 | ::
120 |
121 | conda install -c conda-forge statsmodels
122 |
123 |
124 | Viewing slideshows
125 | ==================
126 | The lectures are all Jupyter notebooks built with the
127 | [RISE](https://github.com/damianavila/RISE) live notebook presentation plugin.
128 | If you install RISE, you can view them as interactive slideshows (instead of
129 | just notebooks). See the RISE page for more info, or simply:
130 |
131 | ::
132 |
133 | conda install -c damianavila82 rise
134 |
135 | Acknowledgments
136 | ===============
137 |
138 | Significant portions of this course were adapted from the following sources,
139 | all of which are licensed under Creative Commons:
140 |
141 | - `swcarpentry/python-novice-gapminder `_
142 | - `TomAugspurger/pydata-chi-h2t `_
143 | - `fonnesbeck/HealthPolicyPython `_
144 | - `jrjohansson/scientific-python-lectures `_
145 |
146 | License
147 | =======
148 | This work is licensed under a
149 | `Creative Commons Attribution 3.0 United States License `_.
150 |
--------------------------------------------------------------------------------
/docs/Makefile:
--------------------------------------------------------------------------------
1 | # Minimal makefile for Sphinx documentation
2 | #
3 |
4 | # You can set these variables from the command line.
5 | SPHINXOPTS =
6 | SPHINXBUILD = python -msphinx
7 | SPHINXPROJ = IHMEPythonCourse
8 | SOURCEDIR = .
9 | BUILDDIR = _build
10 |
11 | # Put it first so that "make" without argument is like "make help".
12 | help:
13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14 |
15 | .PHONY: help Makefile
16 |
17 | # Catch-all target: route all unknown targets to Sphinx using the new
18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19 | %: Makefile
20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
--------------------------------------------------------------------------------
/docs/_build/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | *
3 | # Except this file
4 | !.gitignore
5 |
--------------------------------------------------------------------------------
/docs/_static/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | *
3 | # Except this file
4 | !.gitignore
5 |
--------------------------------------------------------------------------------
/docs/_templates/.gitignore:
--------------------------------------------------------------------------------
1 | # Ignore everything in this directory
2 | *
3 | # Except this file
4 | !.gitignore
5 |
--------------------------------------------------------------------------------
/docs/conf.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- coding: utf-8 -*-
3 | #
4 | # IHME Python Course documentation build configuration file, created by
5 | # sphinx-quickstart on Wed Oct 11 13:16:32 2017.
6 | #
7 | # This file is execfile()d with the current directory set to its
8 | # containing dir.
9 | #
10 | # Note that not all possible configuration values are present in this
11 | # autogenerated file.
12 | #
13 | # All configuration values have a default; values that are commented out
14 | # serve to show the default.
15 |
16 | # If extensions (or modules to document with autodoc) are in another directory,
17 | # add these directories to sys.path here. If the directory is relative to the
18 | # documentation root, use os.path.abspath to make it absolute, like shown here.
19 | #
20 | import os
21 | import sys
22 | # Choosing to make a subdirectory part of the path b/c it won't look
23 | # like a separate module to the students.
24 | sys.path.insert(0, os.path.join(os.path.abspath('.'), '../np_sec'))
25 |
26 |
27 | # -- General configuration ------------------------------------------------
28 |
29 | # If your documentation needs a minimal Sphinx version, state it here.
30 | #
31 | # needs_sphinx = '1.0'
32 |
33 | # Add any Sphinx extension module names here, as strings. They can be
34 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
35 | # ones.
36 | extensions = ['sphinx.ext.autodoc',
37 | 'sphinxcontrib.napoleon',
38 | 'sphinx.ext.doctest',
39 | 'sphinx.ext.mathjax',
40 | 'sphinx.ext.viewcode',
41 | 'sphinx.ext.githubpages']
42 |
43 | # Add any paths that contain templates here, relative to this directory.
44 | templates_path = ['_templates']
45 |
46 | # The suffix(es) of source filenames.
47 | # You can specify multiple suffix as a list of string:
48 | #
49 | # source_suffix = ['.rst', '.md']
50 | source_suffix = '.rst'
51 |
52 | # The master toctree document.
53 | master_doc = 'index'
54 |
55 | # General information about the project.
56 | project = 'IHME Python Course'
57 | copyright = '2017, IHME'
58 | author = 'IHME'
59 |
60 | # The version info for the project you're documenting, acts as replacement for
61 | # |version| and |release|, also used in various other places throughout the
62 | # built documents.
63 | #
64 | # The short X.Y version.
65 | version = '1.0'
66 | # The full version, including alpha/beta/rc tags.
67 | release = '1.0'
68 |
69 | # The language for content autogenerated by Sphinx. Refer to documentation
70 | # for a list of supported languages.
71 | #
72 | # This is also used if you do content translation via gettext catalogs.
73 | # Usually you set "language" from the command line for these cases.
74 | language = None
75 |
76 | # List of patterns, relative to source directory, that match files and
77 | # directories to ignore when looking for source files.
78 | # This patterns also effect to html_static_path and html_extra_path
79 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
80 |
81 | # The name of the Pygments (syntax highlighting) style to use.
82 | pygments_style = 'sphinx'
83 |
84 | # If true, `todo` and `todoList` produce output, else they produce nothing.
85 | todo_include_todos = False
86 |
87 |
88 | # -- Options for HTML output ----------------------------------------------
89 |
90 | # The theme to use for HTML and HTML Help pages. See the documentation for
91 | # a list of builtin themes.
92 | #
93 | html_theme = 'alabaster'
94 |
95 | # Theme options are theme-specific and customize the look and feel of a theme
96 | # further. For a list of options available for each theme, see the
97 | # documentation.
98 | #
99 | # html_theme_options = {}
100 |
101 | # Add any paths that contain custom static files (such as style sheets) here,
102 | # relative to this directory. They are copied after the builtin static files,
103 | # so a file named "default.css" will overwrite the builtin "default.css".
104 | html_static_path = ['_static']
105 |
106 |
107 | # -- Options for HTMLHelp output ------------------------------------------
108 |
109 | # Output file base name for HTML help builder.
110 | htmlhelp_basename = 'IHMEPythonCoursedoc'
111 |
112 |
113 | # -- Options for LaTeX output ---------------------------------------------
114 |
115 | latex_elements = {
116 | # The paper size ('letterpaper' or 'a4paper').
117 | #
118 | # 'papersize': 'letterpaper',
119 |
120 | # The font size ('10pt', '11pt' or '12pt').
121 | #
122 | # 'pointsize': '10pt',
123 |
124 | # Additional stuff for the LaTeX preamble.
125 | #
126 | # 'preamble': '',
127 |
128 | # Latex figure (float) alignment
129 | #
130 | # 'figure_align': 'htbp',
131 | }
132 |
133 | # Grouping the document tree into LaTeX files. List of tuples
134 | # (source start file, target name, title,
135 | # author, documentclass [howto, manual, or own class]).
136 | latex_documents = [
137 | (master_doc, 'IHMEPythonCourse.tex', 'IHME Python Course Documentation',
138 | 'IHME', 'manual'),
139 | ]
140 |
141 |
142 | # -- Options for manual page output ---------------------------------------
143 |
144 | # One entry per manual page. List of tuples
145 | # (source start file, name, description, authors, manual section).
146 | man_pages = [
147 | (master_doc, 'ihmepythoncourse', 'IHME Python Course Documentation',
148 | [author], 1)
149 | ]
150 |
151 |
152 | # -- Options for Texinfo output -------------------------------------------
153 |
154 | # Grouping the document tree into Texinfo files. List of tuples
155 | # (source start file, target name, title, author,
156 | # dir menu entry, description, category)
157 | texinfo_documents = [
158 | (master_doc, 'IHMEPythonCourse', 'IHME Python Course Documentation',
159 | author, 'IHMEPythonCourse', 'One line description of project.',
160 | 'Miscellaneous'),
161 | ]
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/docs/index.rst:
--------------------------------------------------------------------------------
1 | .. IHME Python Course documentation master file, created by
2 | sphinx-quickstart on Wed Oct 11 13:16:32 2017.
3 | You can adapt this file completely to your liking, but it should at least
4 | contain the root `toctree` directive.
5 |
6 | Welcome to IHME Python Course's documentation!
7 | ==============================================
8 |
9 | .. toctree::
10 | :maxdepth: 2
11 | :caption: Contents:
12 |
13 | numpy
14 |
15 |
16 | Indices and tables
17 | ==================
18 |
19 | * :ref:`genindex`
20 | * :ref:`modindex`
21 | * :ref:`search`
22 |
--------------------------------------------------------------------------------
/docs/make.bat:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 |
3 | pushd %~dp0
4 |
5 | REM Command file for Sphinx documentation
6 |
7 | if "%SPHINXBUILD%" == "" (
8 | set SPHINXBUILD=python -msphinx
9 | )
10 | set SOURCEDIR=.
11 | set BUILDDIR=_build
12 | set SPHINXPROJ=IHMEPythonCourse
13 |
14 | if "%1" == "" goto help
15 |
16 | %SPHINXBUILD% >NUL 2>NUL
17 | if errorlevel 9009 (
18 | echo.
19 | echo.The Sphinx module was not found. Make sure you have Sphinx installed,
20 | echo.then set the SPHINXBUILD environment variable to point to the full
21 | echo.path of the 'sphinx-build' executable. Alternatively you may add the
22 | echo.Sphinx directory to PATH.
23 | echo.
24 | echo.If you don't have Sphinx installed, grab it from
25 | echo.http://sphinx-doc.org/
26 | exit /b 1
27 | )
28 |
29 | %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
30 | goto end
31 |
32 | :help
33 | %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
34 |
35 | :end
36 | popd
37 |
--------------------------------------------------------------------------------
/docs/numpy.rst:
--------------------------------------------------------------------------------
1 | =====
2 | Numpy
3 | =====
4 |
5 |
6 | Stage 1: Regular For Loop
7 | -------------------------
8 | Goals: Review functions and loops. Get a look at data.
9 |
10 | Background on GBD Output
11 | ^^^^^^^^^^^^^^^^^^^^^^^^
12 |
13 | We will work with data directly from the GBD outputs for overall
14 | population and mortality for countries. These are life tables for
15 | populations, where each population is classified by
16 |
17 | * ``year_id`` the year for which we have this data.
18 |
19 | * ``age_group_id``, which is an identifier for each age interval. These
20 | tend to be smaller for the young, so 28 is the first year,
21 | 5 is the next four years, and 6, onward are 5-year age intervals
22 | ending with a half-open interval to account for
23 | `Jeanne Calment `_,
24 | who lived to 122 years, 164 days.
25 |
26 | The two values we read
27 | are
28 |
29 | .. math::
30 |
31 | l_x & = \mbox{population at start of age interval}
32 |
33 | {}_nq_x & = \mbox{fraction that die within age interval}
34 |
35 | We often refer to :math:`{}_nq_x` as just :math:`q_x`.
36 | Let's take a look at that data. We'll need some functions that are
37 | provided for you.
38 |
39 | .. autofunction:: gbd_example.years
40 |
41 | .. autofunction:: gbd_example.age_groups
42 |
43 | .. autofunction:: gbd_example.us_male_lx_one
44 |
45 | .. autofunction:: gbd_example.us_male_qx_one
46 |
47 | .. autofunction:: gbd_example.us_male_lx
48 |
49 | .. autofunction:: gbd_example.us_male_lx
50 |
51 |
52 | Logging
53 | ^^^^^^^
54 | Logging is a way to add messages to the code that are a secondary
55 | stream of information, besides what you print or write to disk.
56 | For example::
57 |
58 | LOGGER = logging.getLogger("myfile")
59 | logging.basicConfig(level=logging.INFO)
60 |
61 | LOGGER.info("Going to write the file gbd_out.nc")
62 | LOGGER.debug("The data starts with {}".format(data[0:10]))
63 | if all_wrong:
64 | LOGGER.error("Gone wrong, and this is the situation: {}".format(3))
65 | exit()
66 |
67 |
68 | Python format function help at `Python site `_
69 | and the `formatting site. `_
70 |
71 | ================ ==================================================
72 | Call When to use it
73 | ================ ==================================================
74 | LOGGER.debug Messages that help see if code runs.
75 | LOGGER.info Things users normally need to see.
76 | LOGGER.warn Something's likely going wrong.
77 | LOGGER.error Something's wrong and we'll exit.
78 | LOGGER.exception Something's wrong and the exception says more.
79 | ================ ==================================================
80 |
81 | The ``basicConfig`` call sets which level will print when the job runs.
82 |
83 |
84 | Timing with ``timeit``
85 | ^^^^^^^^^^^^^^^^^^^^^^
86 | The built-in `timeit module `_
87 | can tell us how long it takes for a statement to run.
88 | Calling ``timeit.timeit`` can be a challenge. For instance, assume
89 | we have already defined a ``deaths`` function that multiplies
90 | :math:`l_x` and :math:`q_x`. Then we time it::
91 |
92 | def deaths(lx, qx):
93 | return lx[0] * qx[0]
94 |
95 | def time_deaths():
96 | lx = gbd_example.us_male_lx_one()
97 | qx = gbd_example.us_male_qx_one()
98 | deaths_time = timeit.timeit(
99 | stmt="deaths(lx, qx)",
100 | globals={**globals(), **locals()})
101 | print("Deaths takes {} s".format(deaths_time))
102 |
103 | The ``timeit.timeit()`` function starts a separate Python
104 | sub-environment in which to run the string you give it.
105 | The ``globals`` argument, as shown, is a way to ensure that
106 | it can find the ``deaths()`` function and the local
107 | variables, ``lx`` and ``qx``.
108 |
109 |
110 | Exercise: Examine Input Data
111 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
112 | Ensure ``working.py`` imports the ``gbd_example`` module.
113 | Edit the ``examine_input_data`` function in the ``working.py``
114 | script to print
115 |
116 | * the number of age groups the GBD uses
117 | * the years covered
118 | * Use a loop over the arrays to print two values,
119 | :math:`l_x` for US males in 2010 and
120 | :math:`{}_nq_x\:\times\:l_x` for US males in 2010.
121 | You will need to create a loop index that runs from 0 to the
122 | length of the :math:`l_x` array.
123 |
124 | Do you see a pattern in the columns? The second column is the
125 | number of deaths each year, called :math:`{}_nd_x = {}_nq_x\:l_x`.
126 |
127 | *Explore* Put the for-loop into its own function and time that function.
128 | Use the template ``working.calculate_death(lx, qx)``.
129 |
130 |
131 | Stage 2: Convert to a Numpy Array
132 | ---------------------------------
133 | Goals: Understand how lists and numpy arrays behave differently.
134 |
135 | Creation of Numpy Arrays
136 | ^^^^^^^^^^^^^^^^^^^^^^^^
137 | To convert a list to a numpy array::
138 |
139 | import numpy as np
140 | a = [1.4, 2.7, 3.2]
141 | a_np = np.array(a, dtype=np.float)
142 |
143 | To create a numpy array full of zeros or ones::
144 |
145 | import numpy as np
146 | a = np.zeros((24,), dtype=np.int) # Creates 24 integer zeros
147 | b = np.ones((42,), dtype=np.float) # Creates 42 float ones
148 |
149 | What is ``(24,)``? It's a tuple with one element. If you set
150 | ``x=(24,)``, then ``x[0]==24``.
151 | It often is much more efficient to preallocate arrays. With a Python
152 | list, it's normal to ``append`` to the list. That's rarely used
153 | for Numpy arrays.
154 |
155 | Algebraic Operators in Numpy
156 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
157 | We can manipulate whole arrays at once in Numpy without
158 | for loops. They work elementwise::
159 |
160 | import numpy as np
161 | a = np.array([1.4, 2.7, 3.1], dtype=np.float)
162 | b = np.array([2.3, 4.7, 6.9], dtype=np.float)
163 | c = a + b
164 | d = a * b
165 | e = a / b
166 |
167 | We'll experiment with this in the exercise.
168 |
169 | Find the Size of a Python Object
170 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
171 | There is a Python function that tells you how much memory
172 | an object uses. It's the function ``sys.getsizeof()``,
173 | so it's called with::
174 |
175 | import sys
176 |
177 | def make_something():
178 | a = [100000, 99877, 89777]
179 | a_size_in_bytes = sys.getsizeof(a)
180 | LOGGER.info("a kB {}".format(a_size_in_bytes / 1024))
181 |
182 | Sizes of data in memory or on disk have the units:
183 |
184 | ========= ============== =============================================
185 | Unit Abbreviation Size
186 | ========= ============== =============================================
187 | Bit b A single 0 or 1. 8 bits to a Byte.
188 | Byte B Represents a number between 0 and 256
189 | Kilobyte kB 1024 Bytes. Capital B for byte.
190 | Megabyte MB 1024 KB, approximately :math:`10^6` Bytes
191 | Gigabyte GB 1024 MB, approximately :math:`10^9` Bytes
192 | Terabyte TB 1024 GB, approximately :math:`10^{12}` Bytes
193 | ========= ============== =============================================
194 |
195 | Inline Pytest Tests
196 | ^^^^^^^^^^^^^^^^^^^
197 |
198 | In ``working.py`` is an example of an inline pytest. Any function
199 | that starts with ``test_`` will be called by pytest. Pytest also
200 | has an option to run only those tests that match a substring::
201 |
202 | $ pytest -k calculate_death working.py
203 |
204 | That will search the ``working.py`` file for tests and
205 | pick out the test called ``test_calculate_death`` to run.
206 |
207 |
208 |
209 | Exercise: Algebraic Operations
210 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
211 |
212 | 1. Assign ``us_male_lx_one()`` to ``lx``
213 | and ``us_male_qx_one()`` to ``qx``. Work either within a function
214 | or on the command line.
215 |
216 | 2. Find the value of the following::
217 |
218 | lx + lx
219 | lx * 6
220 |
221 | What does each of those operations do?
222 |
223 | 3. Use the template function, called ``working.us_male_np()``
224 | to return two Numpy arrays, one for lx and one for qx.
225 | Then use that function to look at the following::
226 |
227 | lx_np, qx_np = us_male_np()
228 | lx_np + lx_np
229 | lx_np * 3
230 | lx_np * qx_np
231 |
232 | *More* Using numpy arrays, calculation of deaths becomes a one-line
233 | problem. How much faster is the numpy version of calculate death?
234 | There is a template for ``working.calculate_death_np`` you could
235 | fill out and time.
236 |
237 | 4. How do numpy arrays behave differently from lists? This behavior
238 | is called a "pointwise" or "elementwise" operation. Statisticians
239 | call the multiplicative version the
240 | `Hadamard product `_
241 | because they like to think they invent things.
242 |
243 | 5. *More* Find the size in memory of a Python list for :math:`l_x`.
244 | Compare it with the size of the Numpy array for :math:`l_x`.
245 |
246 | 7. *Explore* Make a new list that's a hundred times longer for each.
247 | (Hint, the line ``lx * 6`` copies ``lx`` 6 times.)
248 | Again, find the size with ``getsizeof``.
249 | How much more memory does each float require for a numpy
250 | array? How does that compare with the number of bytes
251 | required to represent a float?
252 |
253 | Stage 3: Numpy Data Structure, Data Types
254 | -----------------------------------------
255 | Goals: Select elements from numpy arrays and understand type promotion.
256 |
257 | The Array Object
258 | ^^^^^^^^^^^^^^^^
259 | A numpy array object has members and methods. The two most important
260 | are the shape and dtype::
261 |
262 | >>> a=np.array([1,2,17,4])
263 | >>> a.shape
264 | (4,)
265 | >>> len(a)
266 | 4
267 | >>> a.dtype
268 | dtype('int64')
269 | >>> a.data
270 |
271 |
272 | The ``data`` member is where numpy stores the numbers 1, 2, 3, 4
273 | in a highly-efficient format. We can't access them except through the
274 | item accessor ([]), as described in
275 | `array indexing `_,
276 | which follows the same basic moves as lists::
277 |
278 | >>> a=np.array([1,2,17,4])
279 | >>> print(a[2])
280 | 17
281 | >>> a[1] = 81
282 | >>> print(a)
283 | [1 81 17 4]
284 | >>> print(a[1:3])
285 | [2 17]
286 | >>> print(a[:3])
287 | [1 2 17]
288 | >>> print(a[-1]
289 | 4
290 | >>> print(a[:])
291 | [1 2 17 4]
292 |
293 | In addition, a numpy array can index two other ways. One is
294 | to index with an array of indices::
295 |
296 | >>> a=np.array([1,2,17,4])
297 | >>> a[ [0, 3] ]
298 | [1 4]
299 |
300 | The other is to index with a sequence of True and False::
301 |
302 | >>> a=np.array([1,2,17,4])
303 | >>> a[ [False, True, True, True] ]
304 | [2 17 4]
305 |
306 | The sequence of True and False has to be the same length as
307 | the array.
308 |
309 | Lastly, numpy can index multiple dimensions using a comma,
310 | so::
311 |
312 | >>> a = np.array([[0, 1], [7, 9]])
313 | >>> a[0, :]
314 | [0 1]
315 | >>> a[:, 0]
316 | [0 7]
317 |
318 | Data Types
319 | ^^^^^^^^^^
320 | The Python language defines a set of types, which include::
321 |
322 | >>> type("hiya")
323 |
324 | >>> type(3)
325 |
326 | >>> type(3.3)
327 |
328 | >>> type(True)
329 |
330 | >>> type(None)
331 |
332 | >>> type(object())
333 |
334 |
335 | It also defines conversions among those types::
336 |
337 | >>> float(3)
338 | 3.0
339 | >>> int(True)
340 | 1
341 | >>> bool(11)
342 | True
343 |
344 | The numpy type system is much more precise about
345 | `numbers `_,
346 | and **every value in the array must have the same type.**
347 |
348 | ========= =================================================================
349 | dtype Use
350 | ========= =================================================================
351 | np.int8 An 8-bit integer, represents -128 to 128.
352 | np.int This is always an alias for an integer the size of Python's int.
353 | np.float This is an alias for a real number the size of Python's float.
354 | np.single A real number with 8 bytes of information, very rarely used.
355 | np.double A real number with 16 bytes, our default.
356 | np.bool This is an alias for a PPython bool.
357 | ========= =================================================================
358 |
359 | The numbers are called dtypes because they are most often used
360 | as the ``dtype`` argument to creating arrays like this::
361 |
362 | lx = np.ones((24,), dtype=np.float)
363 | age_group_id = np.zeros((24,), dtype=np.int)
364 |
365 | Numpy arrays convert all at once::
366 |
367 | lx_ieee = lx.astype(np.double)
368 | lx_int = lx.astype(np.int)
369 |
370 | Converting from a float to an integer truncates the fractional part.
371 |
372 |
373 | Exercise: Array Type
374 | ^^^^^^^^^^^^^^^^^^^^
375 |
376 | *Core* Use ``us_male_np`` to retrieve :math:`l_x` and :math:`{}_nq_x`
377 | as numpy arrays. How does the ``dtype`` of these arrays change
378 | as we do the following?
379 |
380 | * Convert it to integers with ``astype``
381 | * Subtract the integer version from the floating point version
382 |
383 | If we pick out one value from the integer :math:`l_x`, does it
384 | work in Python the same way a normal integer would? For instance,
385 | what if I pass the fourth entry to ``list(range( lx_int[3] ))``?
386 | Do I get a list of integers from 0 to lx_int[3]?
387 |
388 | *More* Let's try a 2D array. Convert ``us_male_lx()`` to a numpy
389 | array and look at the shape. Can you retrieve all results for
390 | one year? How about all results for one age group?
391 | Convert this to an integer and look at the dtype.
392 |
393 | The 2D array covers all years and age groups for US males.
394 | Look at ``gbd_example.years()`` to find the ages for
395 | 2010. How do you find the index of 2010 within the numpy array?
396 | You might need to look at numpy documentation.
397 |
398 | *Explore* Data types matter. Compare the following::
399 |
400 | np.float(1.0) / np.float(0.0)
401 | np.double(1.0) / np.double(0.0)
402 |
403 | How do they differ? Why do they differ? Which would you prefer
404 | for scientific work?
405 |
406 |
407 | Stage 4: Selection Within Arrays
408 | --------------------------------
409 | Goals: Select using arrays of indices or truth values.
410 |
411 | Comparison Operators
412 | ^^^^^^^^^^^^^^^^^^^^
413 | Just as +, -, ``*``, and / operate on arrays, so do logical operators
414 | such as ``==``, ``<``, ``>``. These operations return arrays of booleans::
415 |
416 |
417 | >>> a = np.array([3, 5, 7, 9])
418 | >>> a < 7
419 | [True True False False]
420 |
421 | We looked at indexing before and saw that the colon, :, represents
422 | all the numbers in an axis. We can also use boolean vectors to
423 | select members of an array::
424 |
425 | >>> a = np.array([3, 5, 7, 9])
426 | >>> a[ [True False False True] ]
427 | [3 9]
428 |
429 | Combine the logical operator's output with the selection input,
430 | and you get a powerful way to select sections arrays::
431 |
432 | >>> a = np.array([3, 5, 7, 9])
433 | >>> a[ a < 7 ]
434 | [3 5]
435 | >>> len(a[ a == 9 ])
436 | 1
437 |
438 | Truth of a Boolean Array
439 | ^^^^^^^^^^^^^^^^^^^^^^^^
440 | We can't ask if an array of True and False is True.
441 | Instead, we use two operators, All and Any::
442 |
443 | >>> a = np.array([3, 5, 7, 9])
444 | >>> all(a > 0)
445 | True
446 | >>> any(a < 4)
447 | True
448 | >>> any(a > 20)
449 | False
450 | >>> if a > 15000:
451 | print(3)
452 | else:
453 | print(4)
454 |
455 | Traceback (most recent call last):
456 | File "", line 1, in
457 | ValueError: The truth value of an array with more than one element
458 | is ambiguous. Use a.any() or a.all()
459 |
460 | You may see that error message at some point, and ``any()`` or ``all()``
461 | are the solution.
462 |
463 |
464 | Index Where
465 | ^^^^^^^^^^^
466 | We often want to know for which elements of the array something
467 | is true. This is called an ``argwhere`` function, but in numpy
468 | it's just ``np.where()``::
469 |
470 | >>> a = np.array([3, 5, 7, 9])
471 | >>> np.where(a > 5)
472 | (array([2, 3]),)
473 | >>> lows = np.where(a < 7)[0]
474 | >>> lows
475 | array([0, 1])
476 |
477 | Note that ``np.where`` returns a tuple, and the places where
478 | the condition is True are the first element of the tuple.
479 |
480 | Exercises
481 | ^^^^^^^^^
482 |
483 | Using the numpy versions of :math:`l_x` and :math:`{}_nq_x`,
484 | let's try subselecting them. What is lx when :math:`l_x < 90,000`?
485 | For which indices is :math:`l_x < 90,000`?
486 |
487 | Is there any age group for which the deaths (``lx * qx``)
488 | are greater than 15,000? 20,000?
489 |
490 | *More* If you know for which indices :math:`l_x < 10,000`,
491 | then can you find which age group IDs correspond to those
492 | indices? Can you set :math:`l_x` to 0 at those points?
493 |
494 |
495 | Stage 5: Collective Operations
496 | ------------------------------
497 | Goals: Recognize collective operations and be able to find available tools.
498 |
499 | A collective operation is an operation on a set of things.
500 | This is not a collective operation::
501 |
502 | lx_np = np.array(gbd_example.us_male_lx_one())
503 | for lx in range(1, len(lx_np)):
504 | dx = lx[idx-1] - lx[idx]
505 |
506 | This is a collective operation, another way to compute deaths
507 | from the given data::
508 |
509 | dx = lx[:-1] - lx[1:]
510 |
511 | In the language of Python, a ``ufunc`` is a function that acts
512 | elementwise on an array. For instance, we can's use Python's ``sin``
513 | function to get the sine of values, but numpy defines a ``ufunc``
514 | version we can use::
515 |
516 | import math
517 | import numpy as np
518 |
519 | arr = np.array([0.9, 0.7, 0.6], dtype=np.float)
520 | try:
521 | result = sin(arr)
522 | except TypeError as te:
523 | print("Cannot get the sin of an array using built-in sin")
524 |
525 | # But the numpy version is a ufunc, so it applies across all.
526 | print(np.sin(arr))
527 |
528 | We default to using the
529 | `numpy versions `_
530 | of functions when possible.
531 |
532 | Scipy Library
533 | ^^^^^^^^^^^^^
534 | Numpy is the common language for almost all Python mathematics.
535 | The `Scipy Tutorial `_
536 | is a good place to start.
537 | Using it gives you access to
538 | `Scipy `_, which has a wide range
539 | of computational functions. Many operations in Scipy are ufuncs.
540 |
541 | Exercise: Using Scientific Functions
542 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
543 |
544 | We often work in logit space. Find the logit function and convert
545 | :math:`{}_nq_x` to logit space. Use expit to convert it back.
546 | Use ``np.allclose`` to see if the converted one matches the original.
547 |
548 | Use this time to look through scipy. Which functions look like they will
549 | be most useful for work here?
550 |
551 | Stage 6: From Numpy to Pandas
552 | -----------------------------
553 | Goals: Understand need for Pandas.
554 |
555 | Dictionaries
556 | ^^^^^^^^^^^^
557 | A `dictionary `_
558 | is a data structure that maps keys to values.
559 | The keys have to be immutable, and the values can be any object.
560 |
561 | There are several ways to create a dictionary::
562 |
563 | empty_dict = dict()
564 | pop_map = { 28: 100000, 5: 999966 }
565 | coords = dict(year_id=[1990, 1991], sex_id=[1, 2, 3])
566 | coords = {"year_id": [1990, 1991], "sex_id": [1, 2, 3]}
567 |
568 | The last two lines do the same thing.
569 | Once you make it, entries can be read or added with item accessors,::
570 |
571 | print(coords["year_id"])
572 | pop_map[6] = 999700
573 |
574 | Exercise: Access by Age Group
575 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
576 | The goal is to access ``lx`` using age group ID instead
577 | of the 0-based index into ``lx``. It will look like this::
578 |
579 | >>> print(lx[ by_age[ 28 ] ])
580 | 100000.0
581 |
582 | The ``by_age`` variable refers to a dictionary whose keys
583 | are age_group_ids and whose values are 0-based indices.
584 | Retrieve age group IDs using ``gbd_example.age_groups()``
585 | and create that dictionary.
586 |
587 | Would you rather write code using the 0-based index or using
588 | the dictionary-based index? What are the pros and cons of
589 | each for correctness and speed?
590 |
--------------------------------------------------------------------------------
/np_sec/answers.py:
--------------------------------------------------------------------------------
1 | """
2 | These are answers to the questions in this part of the course.
3 | """
4 | from argparse import ArgumentParser, RawTextHelpFormatter
5 | import logging
6 | import os
7 | from pathlib import Path
8 | import sys
9 | import timeit
10 |
11 | import numpy as np
12 |
13 | import gbd_example
14 |
15 |
16 | LOGGER = logging.getLogger("answers")
17 |
18 |
19 | def examine_input_data():
20 | years = gbd_example.years()
21 | age_groups = gbd_example.age_groups()
22 | lx = gbd_example.us_male_lx_one()
23 | qx = gbd_example.us_male_qx_one()
24 |
25 | LOGGER.info("All years: {}".format(", ".join(str(y) for y in years)))
26 | LOGGER.info("Age group count: {}".format(len(age_groups)))
27 | LOGGER.debug("lx males 2010 {}".format(lx))
28 | LOGGER.debug("qx males 2010 {}".format(qx))
29 |
30 | for idx in range(len(lx)):
31 | print(lx[idx], lx[idx] * qx[idx])
32 |
33 |
34 | def compare_list_array():
35 | lx = gbd_example.us_male_lx_one()
36 | qx = gbd_example.us_male_qx_one()
37 | lx_np = np.array(lx)
38 | qx_np = np.array(qx)
39 |
40 | print("add lx {}".format(lx + lx))
41 | print("mult lx {}".format(lx * 3))
42 | print("add lx_np {}".format(lx_np + lx_np))
43 | print("mult lx_np {}".format(lx_np * 3))
44 | print("mult lx_np {}".format(lx_np * qx_np))
45 |
46 |
47 | def deaths(lx, qx):
48 | deaths = list()
49 | for idx in range(len(lx)):
50 | deaths.append(lx[idx] * qx[idx])
51 | return deaths
52 |
53 |
54 | def test_calculate_death():
55 | dx = deaths(gbd_example.us_male_lx_one(),
56 | gbd_example.us_male_qx_one())
57 | assert np.allclose(dx, gbd_example.us_male_dx_one())
58 |
59 |
60 | def deaths_np(lx, qx):
61 | return lx * qx
62 |
63 | def time_deaths():
64 | lx = gbd_example.us_male_lx_one()
65 | qx = gbd_example.us_male_qx_one()
66 | deaths_time = timeit.timeit(
67 | stmt="deaths(lx, qx)",
68 | globals={**globals(), **locals()})
69 | print("Deaths takes {} s".format(deaths_time))
70 |
71 |
72 | def time_deaths_np():
73 | lx = np.array(gbd_example.us_male_lx_one())
74 | qx = np.array(gbd_example.us_male_qx_one())
75 | deaths_time = timeit.timeit(
76 | stmt="deaths_np(lx, qx)",
77 | globals={**globals(), **locals()})
78 | print("Deaths_np takes {} s".format(deaths_time))
79 |
80 |
81 | if __name__ == "__main__":
82 | parser = ArgumentParser(description=__doc__,
83 | formatter_class=RawTextHelpFormatter)
84 | parser.add_argument("-v", action="count", default=0)
85 | parser.add_argument("-q", action="count", default=0)
86 | args, _ = parser.parse_known_args()
87 | logging.basicConfig(level=logging.INFO - 10 * args.v + 10 * args.q)
88 |
89 | #examine_input_data()
90 | compare_list_array()
91 | time_deaths()
92 | time_deaths_np()
93 |
--------------------------------------------------------------------------------
/np_sec/gbd_example.jinja:
--------------------------------------------------------------------------------
1 | import logging
2 |
3 | import numpy as np
4 |
5 |
6 | LOGGER = logging.getLogger("ihme_python_course.numpy.gbd_example")
7 |
8 |
9 | def years():
10 | """
11 | Retrieve list of years.
12 |
13 | Returns:
14 | A list of years for this data.
15 | """
16 | return {{ years }}
17 |
18 |
19 | def age_groups():
20 | """
21 | These are the IDs as defined by GBD.
22 |
23 | Returns:
24 | A list of age group IDs, in chronological order.
25 | """
26 | return {{ age_group }}
27 |
28 |
29 | def us_male_lx_one():
30 | """
31 | :math:`l_x` for males in the US in the year 2010.
32 |
33 | Returns:
34 | list[float] of :math:`l_x` at the start of each interval.
35 | """
36 | return {{ us_male_lx_2010 }}
37 |
38 | def us_male_qx_one():
39 | """
40 | :math:`{}_nq_x` for males in the US in the year 2010.
41 |
42 | Returns:
43 | list[float] of :math:`{}_nq_x` across each interval.
44 | """
45 | return {{ us_male_qx_2010 }}
46 |
47 |
48 | def us_male_dx_one():
49 | lx = np.array(us_male_lx_one(), dtype=np.float)
50 | qx = np.array(us_male_qx_one(), dtype=np.float)
51 | return list(lx * qx)
52 |
53 |
54 | def us_male_lx():
55 | """
56 | :math:`l_x` for males in the US for all GBD years.
57 |
58 | Returns:
59 | list[list[float]] of :math:`q_x` across each interval.
60 | """
61 | return {{ us_male_lx }}
62 |
63 |
64 | def us_male_qx():
65 | """
66 | :math:`{}_nq_x` for males in the US for all GBD years.
67 |
68 | Returns:
69 | list[list[float]] of :math:`{}_nq_x` across each interval.
70 | """
71 | return {{ us_male_qx }}
72 |
--------------------------------------------------------------------------------
/np_sec/prepare_data.py:
--------------------------------------------------------------------------------
1 | """
2 | This script converts GBD output into a format suitable for the course.
3 | It relies on methods and libraries not discussed within the course.
4 | The GBD output was read earlier by a script that reads db_queries
5 | and produces XArray versions of that data.
6 | """
7 | from argparse import ArgumentParser, RawTextHelpFormatter
8 | import logging
9 | import os
10 | from pathlib import Path
11 |
12 | from jinja2 import Template
13 | import numpy as np
14 | import xarray as xr
15 |
16 | import fbd_core.demog
17 |
18 |
19 | LOGGER = logging.getLogger("ihme_python_course.np_sec.prepare_data")
20 | GBDDATA = Path("/ihme/forecasting/data/4/past/"
21 | "life_expectancy/20171006_shock_hiv")
22 |
23 | def translate_data(gbd_path):
24 | """
25 | Reads input data files and outputs Python data structures.
26 | The postcondition is that those files will be sorted according
27 | to the age at which age intervals begin, so they will be in age order.
28 |
29 | :param gbd_path:
30 | :return: A dictionary of lx, qx.
31 | """
32 | qx_file = gbd_path / "gbd_qx.nc"
33 | lx_file = gbd_path / "gbd_lx.nc"
34 | LOGGER.info("opening files {} {}".format(qx_file, lx_file))
35 | qx_xr = xr.open_dataarray(str(qx_file))
36 | lx_xr = xr.open_dataarray(str(lx_file))
37 | age_ids = lx_xr.age_group_id.values.copy()
38 | # Incoming data usually has the youngest age group out of order.
39 | # 28 is the youngest age group, so move it to front.
40 | LOGGER.debug("age_ids in {}".format(age_ids))
41 | loc28 = np.where(age_ids == 28)[0][0]
42 | LOGGER.debug("loc of 28 {}".format(loc28))
43 | age_ids[loc28] = 1
44 | would_sort = age_ids.argsort()
45 | age_sort = lx_xr.age_group_id.values[would_sort]
46 | LOGGER.debug("would sort {}".format(would_sort))
47 | lx_sort = lx_xr.loc[dict(age_group_id=age_sort)]
48 | LOGGER.debug("age_ids in qx {}".format(qx_xr.age_group_id.values))
49 | a = set(qx_xr.age_group_id.values)
50 | b = set(lx_xr.age_group_id.values)
51 | LOGGER.debug("qx lx diff {} {}".format(a - b, b - a))
52 | qx_sort = qx_xr.loc[dict(age_group_id=age_sort)]
53 | return {"lx": lx_sort, "qx": qx_sort}
54 |
55 |
56 | def choose_inputs(gbd_data):
57 | """
58 | Creates a Python module that contains data in a simple list
59 | format.
60 |
61 | :param gbd_data:
62 | :return:
63 | """
64 | template = Template(open("gbd_example.jinja", "r").read())
65 | lx = gbd_data["lx"]
66 | us_men_2010 = dict(location_id=102, sex_id=1, year_id=2010)
67 | vals = dict()
68 | vals["us_male_lx_2010"] = list(lx.loc[us_men_2010].values)
69 | us_men = dict(location_id=102, sex_id=1)
70 | vals["us_male_lx"] = list(list(y) for y in lx.loc[us_men].T.values)
71 | vals["years"] = list(lx.year_id.values)
72 | vals["age_group"] = list(lx.age_group_id.values)
73 | qx = gbd_data["qx"]
74 | vals["us_male_qx_2010"] = list(qx.loc[us_men_2010].values)
75 | vals["us_male_qx"] = list(list(y) for y in qx.loc[us_men].T.values)
76 |
77 | LOGGER.info("Writing file gbd_example.py")
78 | with open("gbd_example.py", "w") as gbd_out:
79 | gbd_out.write(template.render(**vals))
80 | gbd_out.write(os.linesep)
81 |
82 |
83 | if __name__ == "__main__":
84 | parser = ArgumentParser(description=__doc__,
85 | formatter_class=RawTextHelpFormatter)
86 | parser.add_argument("-v", action="count", default=0)
87 | parser.add_argument("-q", action="count", default=0)
88 | parser.add_argument("--input", type=Path, help="Directory with input data",
89 | required=False, default=GBDDATA)
90 | args, _ = parser.parse_known_args()
91 | logging.basicConfig(level=logging.INFO - 10 * args.v + 10 * args.q)
92 |
93 | local_path = Path("./data")
94 | if args.input.exists():
95 | input_path = args.input
96 | elif local_path.exists():
97 | input_path = local_path
98 | else:
99 | raise RuntimeError("Cannot find input path {}".format(args.input))
100 |
101 | arrays = translate_data(input_path)
102 | choose_inputs(arrays)
--------------------------------------------------------------------------------
/np_sec/working.py:
--------------------------------------------------------------------------------
1 | """
2 | This is a file in which to work.
3 | """
4 | from argparse import ArgumentParser, RawTextHelpFormatter
5 | import logging
6 | import sys
7 | import timeit
8 |
9 |
10 | LOGGER = logging.getLogger("working")
11 |
12 |
13 | def examine_input_data():
14 | # Get lx and qx from our input module, gbd_example.
15 |
16 | # Create a list into which to put the results
17 |
18 | # Loop over the arrays, and store into the result list
19 |
20 | # print the result list
21 | LOGGER.debug("examine_input_data begin")
22 |
23 |
24 | def calculate_death(lx, qx):
25 | """
26 | Given population and mortality, return the deaths for each interval.
27 |
28 | Arguments:
29 | lx (list[float]): :math:`l_x`, population at start of each interval
30 | qx (list[float]): :math:`{}_nq_x`, mortality over each interval
31 |
32 | Returns:
33 | list[float]: :math:`d_x = l_x\:{}_nq_x` deaths
34 | """
35 | return dx
36 |
37 |
38 | def test_calculate_death():
39 | dx = calculate_death(gbd_example.us_male_lx_one(),
40 | gbd_example.us_male_qx_one())
41 | assert np.allclose(dx, gbd_example.us_male_dx_one())
42 |
43 |
44 | def calculate_death_np(lx, qx):
45 | """
46 | Given population and mortality, return the deaths for each interval.
47 |
48 | Arguments:
49 | lx (np.array): :math:`l_x`, population at start of each interval
50 | qx (np.array): :math:`{}_nq_x`, mortality over each interval
51 |
52 | Returns:
53 | list[float]: :math:`d_x = l_x\:{}_nq_x` deaths
54 | """
55 | return dx
56 |
57 |
58 | def us_male_np():
59 | """
60 | Returns :math:`l_x` and :math:`{}_nq_x` as numpy arrays.
61 |
62 | Returns:
63 | Tuple containing lx, qx.
64 | """
65 | # Get lx and qx from our input module, gbd_example.
66 |
67 | # Convert them to numpy arrays
68 |
69 | # And return them both
70 | return (lx_np, qx_np)
71 |
72 |
73 | if __name__ == "__main__":
74 | parser = ArgumentParser(description=__doc__,
75 | formatter_class=RawTextHelpFormatter)
76 | parser.add_argument("-v", action="count", default=0,
77 | help="Add -v to increase verbosity.")
78 | parser.add_argument("-q", action="count", default=0,
79 | help="Add -q to quiet logging.")
80 | args, _ = parser.parse_known_args()
81 | logging.basicConfig(level=logging.INFO - 10 * args.v + 10 * args.q)
82 |
83 | examine_input_data()
84 |
--------------------------------------------------------------------------------