ECON 370 Quantitative Economics With Python
ECON 370 Quantitative Economics With Python
ECON 370 Quantitative Economics With Python
January 2016
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Agenda ...
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Office Hours
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Nature of programming
But over time your toolkit grows and pretty quickly you start to piece
programs together that do really useful things ...
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Computers ...
How do computers work?
Hardware Level
Having a bit of knowledge of how the system works can help when
writing programs that ultimately provide instructions to that
underlying system.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Programming
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Code gets translated from high level to low level instructions through:
1. Interpreters
2. Compilers
Even between high level languages there are lots of reasons why they
will differ in speed.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Language Comparison: C
#include <stdio.h>
int main()
{
printf(”Hello world\n”);
return 0;
}
./a.out
”Hello World”
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
.file ”simple.c”
.section .rodata
.LC0:
.string ”Hello world”
.text
.globl main
.type main, @function
main:
.LFB0:
.cfi_startproc
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset 6, -16
movq %rsp, %rbp
.cfi_def_cfa_register 6
movl $.LC0, %edi
call puts
movl $0, %eax
popq %rbp
.cfi_def_cfa 7, 8
ret
.cfi_endproc
.LFE0:
.size main, .-main
.ident ”GCC: (Ubuntu 4.8.4-2ubuntu1~14.04) 4.8.4”
.section .note.GNU-stack,””,@progbits
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Elements of a program
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
The first 3 weeks of this course will be a crash course on Python ...
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Quick Survey
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
What is Python?
Python has experienced rapid adoption in the last decade and is now
one of the most popular programming languages.
http://githut.info/
1 . . . . . . . . . . . . . . . . . . . .
started in 1989 by Guido van Rossum . . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Why Python?
Python is:
1. free
2. a full programming environment
3. easier to learn than some other languages
4. highly productive
• Large library of user contributed packages
• high level language design
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Python Usage
Scientific Community
1. Machine Learning
2. Astronomy
3. Artificial Intelligence
4. Chemistry
5. Biology
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Python Features
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
• Pro
• More packages are available in Python 2.7
• A lot of examples are written in Python 2.7 syntax.
• Con
• In maintenance mode - not getting new features as the language
develops over time.
• Pro
• Newest version which is the long term future of Python
• Most of the scientific stack has been ported to Python 3
• Con
• Sometimes want to use a library which has not been migrated to
Python 3 yet. (but can make use of conda environments if needed)
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
XKCD Cartoon:
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Start with small programs and then move onto larger applications.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Otherwise
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
1. python REPL2
2. ipython REPL
3. jupyter
2 . . . . . . . . . . . . . . . . . . . .
Read-Eval-Print Loop . . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
IDE’s
There are a couple of interesting IDE environments that can also make
working with Python a little easier. The best is probably ...
Spyder IDE
Demo
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Down the track - you may wish to start writing your python code in a
full text editor.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Demo
1. Syntax highlighting
2. More productive (tab completion, auto-indentation)
3. Regex and pattern matching
4. ...
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Workflow
Feel free to check out the tools that are available and come up with a
workflow that is best for you ...
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Jupyter
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
MyBinder
You can click on the “mybinder” badge in the repo to launch a live
environment running Python 3.5 with the course notebooks.
However these notebooks are not stateful. They will not retain your
edits and are really an exploratory service.
You can also run the notebooks locally by downloading them to your
computer and running Jupyter.
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
1. Notebook Basics
2. Modal Editing
3. Running Code
4. Text Editor Features (Syntax Highlighting etc.)
5. Tab Completion
6. Object Introspection
7. Working with the shell
8. Working with Files
9. First Python Program
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
1. Introductory Example
2. Basic Structure of a Python Program
3. Variables
4. Data Types
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .
Intro to Programming Python Python Installation Jupyter Notebooks
Additional References
Additional References:
. . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . .