Date | Session | Title | Description |
---|---|---|---|
Day 1 | Lecture 1 | Intro and Setup | Why Python, Setup, etc |
Day 1 | Lecture 2 | Basic Python | Syntax, data structures, control flow, etc |
Day 2 | Lecture 3 | Numpy + Pandas I | Numpy basics, series/dataframe basics |
Day 2 | Lecture 4 | Pandas II | Joining, advanced indexing, reshaping, etc |
Day 3 | Lecture 5 | Pandas III | Grouping, apply, transform, etc |
Day 3 | Lecture 6 | Plotting | Intro to plotting in Python |
Day 3 | Lecture 7 | Intro to Modeling | Intro to stats/ML models in Python |
First, you're going to want to get a copy of this repository onto your
machine. Simply fire up git
and clone it:
Open up a shell (e.g. git.exe
, cmd.exe
, or terminal.app
)
Navigate to where you'd like to save this.
~/repos/
(e.g. C:/Users/<user>/repos/
on Windows, /Users/<user>/repos/
on Mac, or /home/<user>/repos/
on Unix).Clone this repo: git clone https://github.com/ihmeuw/ihme-python-course.git
If you need help with setting up git
, see this page or simply download the repo as a zip file for now...
via xkcd (see also xkcd in python and xkcd for matplotlib)
Python is a widely used high-level, general-purpose, interpreted, dynamic programming language.
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.
There are modules available for just about anything you could want to do in Python, with nearly 100,000 available on PyPI alone. Some notable packages:
DataFrame
class is useful for spreadsheet-like representation and mannipulation of data. Also includes high-level plotting functionality.python
at the command line will open up the standard Python interpreter:`python my-program.py`
IPython is an interactive interpreter for Python that adds many user-friendly features on top of the standard python
:
Start IPython by simply calling ipython
from the command line:
Jupyter notebooks are HTML-based environments for IPython, R, and more, which allow you to interactively code, explore your data, and integrate documentation
This is a Jupyter notebook
Starting a Jupyter notebook server will launch a local webserver that you can view in your browser to create, view, and run notebooks:
jupyter notebook
Spyder is a MATLAB-like IDE for scientific computing with Python
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
Calling Spyder will open up a new project
spyder
Another interesting new IDE for Python is Rodeo
Go to the Anaconda download page and download the installer for Python 3.5 (64-bit) and simply click through to follow the instructions
If you'd like to setup a Docker container with Anaconda, check out the Docker setup instructions. But be warned that it doesn't play terribly nicely with Windows 7 or 8...
from IPython.display import Markdown, display
display(Markdown(open('./Exercise 1/README.md', 'r').read()))
See the README for instructions on how to install Anaconda on your system.
See the README again for instructions on cloning this repo
(into its recommended location of ~/repos/
).
python
interpreter¶python
at the command line1 + 1
1.0 + 1
"hello world"
print("hello world")
exit()
to exitipython
¶ipython
print?
and hit return
print(
and hit tab
exit()
to exitjupyter notebook
¶~/repos/ihme-python-course
)jupyter notebook
to startup a notebook server8888
it might start
the server on a different port. Look for a message in your terminal
like
The Jupyter Notebook is running at: http://localhost:8889/
to find it.Lecture 1/Exercise 1
directory and
and then click on test-notebook.ipynb
to open itpython my-script.py
RISE
¶RISE
will add a new button to your
Jupyter toolbar that'll allow you to view these notebooks in slideshow modespacebar
and shift+spacebar
to navigate through the slidesView > Cell Toolbar > Slideshow