Skip to content

scottpham/nicar19-geopandas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Intro

GeoPandas is an extremely useful and mostly user-friendly tool for doing basic GIS analysis and plotting in Python. I use it more frequently than QGIS or other tools because it integrates nicely with Jupyter Notebooks and uses Pandas under the hood, both of which are regular parts of my daily data journalism toolkit.

It's important to realize that GeoPandas is really just a nice wrapper around a bunch of other useful Python libraries including Pandas, Matplotlib, Fiona, Shapely and others. If you want to do something complicated that's not covered by the GeoPandas documentation, there's a good chance you can still do it by looking at the documentation for one of those other libraries.

Getting started

This project uses a Pipenv to manage all the Python libraries you'll need and Makefiles to get all the big data files downloaded from the Census and such.

If you've already got Pipenv installed on your machine, just run all these commands in your terminal one after the other in order.

  1. pipenv install
  2. pipenv shell
  3. make all

This last one will take 3-5 minutes. Your terminal might throw a few warnings but as long as it completes, you're fine. Finally, run:

  1. jupyter notebook

And you'll be good to go! All the good stuff is the notebooks folder. Descriptions of those files below:

Notebooks

The instruction files are:

  • 1_basic_mapping.ipynb
  • 2_advanced_mapping.ipynb

Go through these in order. The notebooks use a few datasets that I've cleaned and simplified. The Makefile takes care of that when you set up, but if you're curious, you can see exactly how I've cleaned them in the following notebooks:

  • data_cleaning_counties.ipynb
  • data_cleaning_restaurants.ipynb
  • data_cleaning_states.ipynb

In-n-out dataset:

In data_cleaning_restaurants.ipynb I scrape a website and geocode the addresses using the Google API. Again: you do not have to run this code. The complete scraped and cleaned file is included for you in output/innout/.

If you want to run this code, you'll need to set up your own API Key following the instructions here.

Put your API key in credentials_template.py and then change the name to credentials_template.py.

Helpful links

Geopandas reference

Jonathan Soma's excellent geopandas tutorials

Spatial Reference for getting EPSG numbers

Pyplot options

Spatial join example

Matplotlib colormaps

Matplotlib named colors

Census shapefiles

In-n-out locations

CDC opioid prescription data

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published