IE Python
IE Python
Engineering
with Python
A Brief Tutorial with
Engineering Examples
Tools Used in IE Classes
● Expensive
● Subject Matter Specific
● Each has its own "language"
http://en.wikipedia.org/wiki/Python_(programming_language)
Sample Python Code
Where Can You Start Learning?
● Text Editors
○ http://www.sublimetext.com/
○ http://notepad-plus-plus.org/
● Windows
○ http://www.python.org/download/releases/2.7.3/
● Mac OSX and Linux
○ find the terminal and type "python"
Python in your Browser
● PythonAnywhere
○ PythonAnywhere is a Python development and hosting
environment that displays in your web browser and runs on our
servers. They're already set up with everything you need. It's easy
to use, fast, and powerful.
○ Website hosting with
Django, Flask and other frameworks
○ https://www.pythonanywhere.com/
Python in your Browser
● Wakari by Continuum.io
○ Web-based Python Data Analysis Environment
○ Wakari is a collaborative analytics platform in the browser. It's
Wordpress, Github, and Youtube for science, engineering, and
business data analytics. It allows scientists and data analysts to
easily publish and share their analyses as interactive dashboards,
visualizations, and scientific notebooks that anyone can then
modify.
○ Based on Anaconda, a collection of Python
libraries supported by Continuum.io
○ http://continuum.io/
○ https://www.wakari.io/
Python for IE: Table of Contents
1. Numpy and Scientific Python
a. Quality Control Example
2. Data Manipulation
a. Supply Chain Example
3. Database Integration
4. Graph and Network Problems
a. Web Mining Example
5. Linear Programming
6. Discrete Event Simulation
7. MapReduce
8. Modern Web Applications
a. Client Side Example
b. Server Side Example
9. Summary and Additional Resources
Numpy and Scientific Python
● Numpy
● Key Concepts
○ python is slower compared to compiled lang
○ faster when it comes to working with humans
○ it provides MATLAB like array functions written in
fast C-code, but accessible through a Python
interface
● Numpy QC simple gap simulation example
○ https://github.com/mdlthree/pyIEM/blob/master/qcGapSim.py
○ I was able to compute 10 million samples almost instantly
○ 50 million samples started causing page faults
Data Manipulation
● IPython
● Matplotlib
○ basic version time series
● Pandas
○ easy version time series
● Further Reading
○ http://matplotlib.org/gallery.html
○ http://blog.wesmckinney.com/
○ http://ipython.org/
Time Series Example
● SQLite 3
○ http://www.sqlite.org/
○ Included with the Python Standard Library
○ File Based Database, no server required
● SQLAlchemy
○ http://www.sqlalchemy.org/features.html
○ DB-API abstraction
○ write code once
○ implement with many popular DBs
■ Open Source: PostgreSQL, MySQL, SQLite
■ Proprietary: Microsoft SQL, Oracle
● NetworkX
○ http://networkx.github.com/
○ NetworkX is a Python language software package for the creation,
manipulation, and study of the structure, dynamics, and functions
of complex networks.
● Algorithms
○ Breadth and Depth First Search, All Pairs Shortest Path, Kruskal's
Minimum Spanning Tree, PageRank, Ford-Fulkerson Maximum
Flow, Topological Sort, Matching and many more!
○ http://networkx.github.com/documentation/latest/reference/
● Networkx Example
○ http://www.the-adam.com/
○ A personal blog by Adam Rosenburg Ph.d.
Operations Research
○ A interesting read for Math/OR/IE types with
many personal opinions
○ Problem? Difficult navigation due to lack of any
content management. No direct link to many
pages. You can only discover them through links
deep in the site, and some only by dissecting
URL
○ Lets map ALL THE LINKS!
MSIS 5633: Business Intelligence Tools & Techniques
Web Mining Example (continued...)
● Modules
○ urllib2: retrieving web pages
○ lxml.html: finding <a> tags and storing data
○ NetworkX: page=node, <a>=edge
○ Matplotlib: print the resulting graph
● Mining Strategy
○ Start with the root page { http://www.the-adam.com/ }
○ Add page to nodeList
○ foreach page in nodeList
■ parse HTML, find <a>
■ if <a> is a new page, add it to nodeList
■ add an edge from page to <a>
● https://github.com/mdlthree/pyIEM/blob/master/webMining.py
Linear Programming
SUse
IEM 5013: Intro to Mathematical Programming
Discrete Event Simulation
● SimPy
● https://simpy.readthedocs.org/en/latest
● Looks like a promising alternative to
existing simulation platforms, even if it
doesn't have the fancy 3D animation.
● Disco
○ a distributed computing framework like Hadoop
but written in Python, founded by Nokia
○ http://discoproject.org/
○ http://pyvideo.org/video/961/the-disco-mapreduce-framework
Powered by Python
● Project Euler
● XKCD
● PyVideo
● Standard Python Library Docs
● Wikipedia
● Hacker News
Poster