A Tutorial On geopandas

Article by:
Date Published:
Last Modified:


geopandas is a Python library that adds extra functionality to pandas to make it more useful for dealing with geospatial data.

Most of the code examples below assume you have imported geopandas into the current module with:

import geopandas


geopandas makes it very easy to plot geospatial data onto graphs.

world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
The plot generated by the 'naturalearth_lowres' dataset that is bundled with geopandas.

The plot generated by the ‘naturalearth_lowres’ dataset that is bundled with geopandas.

If you want to save the plot, you can import matplotlib.pyplot and use the standard save_fig() function:

import matplotlib.pyplot as plt

Common Warnings/Errors

Missing package rtree

/usr/local/lib/python3.7/site-packages/geopandas/ UserWarning: Cannot generate spatial index: Missing package `rtree`.

You are missing the package rtree. rtree can not usually easily be installed with pip alone because it depends on a number of dependencies that pip does not manage. It is best to use your systems package manager to install rtree instead.

No module named descartes

ModuleNotFoundError: No module named 'descartes'

Running pip install geopandas does not install the dependency descartes automatically. descartes is needed when plotting, for example when you call .plot(). Install with:

pip install descartes



Related Content:


comments powered by Disqus