Geographic Information Systems
(CE 361 / Math 310)
Dr. Umer Tariq
Assistant Professor,
Dhanani School of Science & Engineering,
Habib University
1
Outline
• Ipython
• Jupyter Notebook
• Google Colab
• Numpy
• Pandas
• GeoPandas
2
Python vs C
3
IPython
• IPython (short for Interactive Python)
• An enhanced Python interpreter
4
IPython: Capabilities Beyond Regular Python
• IPython Magic Commands
• IPython and Shell Commands
• Debugging Support
• Profiling and Timing Support
5
Jupyter Notebooks
• Jupyter project provides browser-based notebooks for Python, Julia, R, and
other programming languages.
• Jupyter/IPython notebook
– A browser-based graphical interface to the IPython shell
– In addition to executing Python/IPython statements, the notebook allows the user to
include formatted text, static and dynamic visualizations, mathematical equations,
JavaScript widgets, and much more.
– These notebooks can be saved in a way that lets other people open them and execute
the code on their own systems.
• Though the Ipython notebook is viewed and edited through your web
browser window, it must connect to a running IPython process in order to
execute code.
6
Google Colab
• [Link]
• Essentially, allows you to create Jupyter notebooks that are stored in your
Google Drive account and are connected to the underlying Ipython
interpreter process on a machine in the Google Cloud.
7
Numpy and Pandas: Why should I care?
• We can think of all data fundamentally as array of numbers
• Efficient mechanisms for storage and manipulation of numerical arrays is
absolutely fundamental to the process of doing data science.
• Specialized tools that are available in Python ecosystem for efficiently
handling such numerical arrays
– Numpy
– Pandas
8
Numpy
• Short for Numerical Python
• Numpy arrays are like Python’s built-in list type, but Numpy arrays provide
much more efficient storage and data operations as arrays grow larger in
size.
• Numpy arrays form the core of nearly the entire ecosystem of data science
tools in Python
• Time spent learning to use Numpy effectively will be valuable no matter
what aspect of data science interest you.
9
C vs Python
10
Statically-Typed Language vs Dynamically-Typed Language
• Statically-typed language
– Requires each variable to be explicitly declared
– Example: C, Java
• Dynamically-typed language
– Skips the explicit declaration of variables
– Example: Python
11
C Integer vs Python Integers
• A C integer is essentially a label for a position in memory whose bytes
encode an integer value
• A Python integer is a pointer to a position in memory containing all the
Python object information, including the bytes that contain the integer
value.
• This extra information in Python integer structure is what allows Python to
be coded so freely and dynamically.
• All this additional information in Python types comes at a cost, which
becomes apparent in structure that combine many of these objects.
12
Python Lists
• Because of Python’s dynamic typing, we
can even create heterogeneous lists:
• But this flexibility comes at a cost
– To allow these flexible types, each item in the
list must contain its own type info and other
information.
• In the special case that all variables are
of the same type, much of this
information is redundant. It can be
much more efficient to store
information in a fixed-type array.
13
Python Lists vs Numpy Array
• It can be much more efficient to store information in a fixed-type array.
14
Python Lists vs Numpy Array
• It can be much more efficient to store information in a fixed-type array.
• Furthermore, computation on fixed-type array would be much more
15
efficient as well.
Fixed-Type Arrays in Python
1. Built in array module (available since Python 3.3)
2. ndarray object of the Numpy package
• While Python’s array object provides efficient storage of array-based data,
Numpy adds to this efficient operations on that data.
16
Creation of Numpy Arrays: From Python Lists
17
Creation of Numpy Arrays: From Scratch
18
Computation using Numpy Arrays: Vectorized Operations
reciprocal_array = 1.0 / big_array
19
Pandas: Data Structures
• At the very basic level, Pandas objects can be thought of as enhanced
versions of NumPy structured arrays in which the rows and columns are
identified with labels rather than simple integer indices.
• Series
– Emulates one-dimensional array
20
Pandas: Data Structures
• At the very basic level, Pandas objects can be thought of as enhanced
versions of NumPy structured arrays in which the rows and columns are
identified with labels rather than simple integer indices.
• Series
– Emulates one-dimensional array
21
Pandas: Data Structures
• At the very basic level, Pandas objects can be thought of as enhanced
versions of NumPy structured arrays in which the rows and columns are
identified with labels rather than simple integer indices.
• Series
– Emulates one-dimensional array
22
Pandas: Data Structures
• At the very basic level, Pandas objects can be thought of as enhanced
versions of NumPy structured arrays in which the rows and columns are
identified with labels rather than simple integer indices.
• DataFrame
– Emulates two-dimensional array
23
Pandas: Data Structures
• At the very basic level, Pandas objects can be thought of as enhanced
versions of NumPy structured arrays in which the rows and columns are
identified with labels rather than simple integer indices.
• DataFrame
– Emulates two-dimensional array
24
GeoPandas: Data Structures
• GeoPandas extends the popular data science library Pandas by adding
support for geospatial data.
• GeoSeries
– A subclass of [Link]
25
GeoPandas: Data Structures
• GeoPandas extends the popular data science library Pandas by adding
support for geospatial data.
• GeoDataFrame
– A subclass of [Link]
26
Reference
• Book
– “Python Data Science Handbook: Essential Tools for Working with Data” by Jake
VanderPlas
• Web Links
– [Link]
– [Link]
27