Note: This post was originally published by Luis Natera on his personal blog. It has been republished here as part of TYN Studio's content.
GeoPandas is a Python library that extends the data types used by Pandas to allow spatial operations on geometric types. If you're working with geographic data—whether it's street networks, administrative boundaries, or points of interest—GeoPandas makes it much easier to analyze and visualize.
Getting Started
The beauty of GeoPandas is that if you already know Pandas, the learning curve is gentle. It uses the same DataFrame structure you're familiar with, but adds geometric columns that understand spatial relationships.
Acquiring Data from OpenStreetMap
Let's start by getting some real-world data using OSMnx:
import osmnx as ox
# Download the street network for Manhattan
G = ox.graph_from_address('Manhattan, New York')
OSMnx gives us a NetworkX graph, but we can easily convert it to GeoPandas DataFrames:
# Convert to GeoDataFrames
nodes, edges = ox.graph_to_gdfs(G)
Now we have two GeoDataFrames: one for intersections (nodes) and one for street segments (edges). These work just like regular Pandas DataFrames, but with added spatial capabilities.
Interactive Visualization
One of GeoPandas' best features is the explore() method, which creates interactive maps:
edges.explore(
column="length",
tooltip="length",
popup=True,
tiles="CartoDB dark_matter",
cmap="inferno_r"
)

This creates an interactive map where you can:
- Pan and zoom
- Click on features to see attributes
- Hover for quick information
- Choose different base map styles
Saving Your Map
You can save the interactive map as an HTML file:
edges_map = edges.explore(
column="length",
tooltip="length",
popup=True,
tiles="CartoDB dark_matter",
cmap="inferno_r"
)
edges_map.save("manhattan_streets.html")
This creates a standalone HTML file you can share with anyone—no Python required to view it.
Why GeoPandas?
GeoPandas shines when you need to:
- Spatial joins: Find which points fall within which polygons
- Distance calculations: Measure distances between features
- Coordinate transformations: Convert between different coordinate systems
- Geometric operations: Buffer points, clip shapes, calculate intersections
- Easy visualization: Quick maps with just a few lines of code
Related Tools
GeoPandas works seamlessly with:
- Pandas: For general data manipulation
- Shapely: For geometric operations (GeoPandas uses this under the hood)
- OSMnx: For downloading street networks
- NetworkX: For network analysis
- OpenStreetMap: As a data source
If you're working with any kind of geographic data in Python, GeoPandas should be in your toolkit. It brings together the best of Pandas' data manipulation capabilities with powerful geospatial analysis in a familiar, intuitive interface.