As may be evident from my other posts in the past, I have a tendency to use Python to solve a lot of the problems I face every day doing research in Geography. In that context, analyzing the 2002 Input Output Model for Washington State, I decided that Graph Theory needs to come into play (Economic Geograhy seems to need more Python(s) around).
In order to achieve this, I used the Excel Spreadsheet provided by the Washington State Office of Financial Management (OFM) and Python in the following way:
- Using the excellent xlrd python module to read Excel data into Python
- Create a multi-node directed graph from the data using NetworkX
- With the amazing power of Python, calculate the Adjacency and Distance Matrices of the graph
- Use xlwd to write back information in an Excel sheet
The results were stunning. The 50×50 matrix of the Washington I/O Model with 2,050 actual transactions takes a little more than a second to generate all the outputs given the Excel spreadsheet. Python to the rescue again, performing the work of geographers in a simple, fast way.
Here is a sample image, generating a directed grap (DiGraph) of the first 10 sectors reported in the Washington State Input Output Model for 2002 (the choice of 10 was to ensure a small, less complex graph so people can see the results better). All transactions are considered, with direction preserved.
The graph above is further analyzed using an adjacency matrix and a distance matrix, reported out as an Excel file.
I will be posting more results soon, and if anyone asks for it, I will clean up the script for release into the wild.

Related posts:

I have a data set of almost 45000 lines and i want to read it from excel worksheet to python and then want to compute the adjacency matrix. as i have tried this in Matlab and i failed because of the memory issues with Matlab. is it possible in Python.
MO,
This should be possible in multiple methods. Are your data in an Excel sheet already? Then using xlrd to read them would be the way to go. As for the adjacency matrix calculation… I assume you have 45,000 nodes. I believe NetworkX can handle this. It also allows you to export a network graph to a numpy matrix populated with adjacency values. Which is very very good indeed, so you can avoid any calculations.
If you want to contact me personally, maybe I can help with your code as well.
Michalis
Hi Michalis,
I just came across your blog today from a review in GIS Development magazine. This is really a fantastic & resourceful blog. You surely have contributed a lot to the GIS community.
Regards
Ruslan
I am a graph theory student i want to generate graphs like completed graphs, complete bipartite graphs and etc… by using python… is it possible… can
any one help me out of it?
my mail id is srisrianand@gmail.com please reply me in mail also if possible…
MIchalis,
This is great. I’m wondering if you could share the Python code for this? FYI I’m just getting into Python for these sorts of applications. Thanks!