Geospatial Data with GeoPandas

GeoPandas extends pandas with a geometry column so you can work with maps, shapes, and locations. A GeoDataFrame behaves like a normal DataFrame but can read shapefiles and GeoJSON, reproject coordinates, run spatial joins, and plot maps.

Learn Geospatial Data with GeoPandas in our free Pandas course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…

Part of the free Pandas course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

Learn what a GeoDataFrame and geometry column are, how to read spatial files, what CRS and projections mean, how spatial joins work, and how to draw a quick map.

What You'll Learn in This Lesson

1 GeoDataFrames and the Geometry Column

A GeoDataFrame is just a pandas DataFrame with one special geometry column holding Shapely shapes — points, lines, or polygons. Every other column behaves like ordinary pandas, so all your filtering and grouping skills carry over directly.

The runnable example below uses plain pandas : storing latitude and longitude as ordinary columns. GeoPandas would wrap these into real Point geometries instead.

2 Reading Files, CRS, and Projections

GeoPandas reads many vector formats with one call, gpd.read_file , including shapefiles and GeoJSON . Each layer carries a CRS (Coordinate Reference System); EPSG:4326 is WGS84 longitude/latitude. Use to_crs to reproject so layers share the same system before you measure or join.

3 Spatial Joins and Plotting Maps

A spatial join ( gpd.sjoin ) combines two layers by how their geometries relate in space — for example, which region polygon each city point falls within — rather than by a shared key. Both layers must share the same CRS. Finally, gdf.plot() draws a quick map with matplotlib.

🎯 Your Turn: Sort the Cities

Before mapping, work with the attribute columns in plain pandas. Fill in the blank to sort the cities from northernmost (highest latitude) to southernmost.

📋 Quick Reference

Task

Code (GeoPandas)

Import

import geopandas as gpd

Read a file

gpd.read_file("data.geojson")

Reproject

gdf.to_crs(3857)

Spatial join

gpd.sjoin(a, b, predicate="within")

Plot a map

gdf.plot(column="pop")

❓ Frequently Asked Questions

You've completed the Pandas course!

Congratulations — that was the final lesson. You started with Series and DataFrames and finished with scaling tools and geospatial analysis. Along the way you mastered selection, cleaning, merging, group-by, dates, aggregation, and the capstone, then explored Dask, Polars, Spark, and GeoPandas for going bigger and further.

🚀 Keep practicing on your own datasets — real data is the best teacher. Well done!

Practice quiz

What does GeoPandas add on top of pandas?

  • Geospatial data structures and operations
  • GPU support
  • A web server
  • Image editing

Answer: Geospatial data structures and operations. GeoPandas extends pandas with geospatial types and operations on vector geometry.

What is the main GeoPandas data structure called?

  • GeoSeries only
  • SpatialFrame
  • GeoDataFrame
  • MapFrame

Answer: GeoDataFrame. A GeoDataFrame is a pandas DataFrame with a special geometry column.

What does the special geometry column hold?

  • Plain numbers
  • Shapely geometry objects like points, lines, polygons
  • Only strings
  • Colors

Answer: Shapely geometry objects like points, lines, polygons. The geometry column stores Shapely geometries such as Point, LineString, and Polygon.

Which function reads shapefiles and GeoJSON into a GeoDataFrame?

  • gpd.open_map
  • pd.read_csv
  • gpd.load_shape
  • gpd.read_file

Answer: gpd.read_file. geopandas.read_file reads many vector formats including shapefiles and GeoJSON.

What does CRS stand for in geospatial data?

  • Coordinate Reference System
  • Cartographic Render Style
  • Central Region Storage
  • Column Row System

Answer: Coordinate Reference System. A CRS (Coordinate Reference System) defines how coordinates map to locations on Earth.

Which attribute and method handle a GeoDataFrame's projection?

  • .srid and .convert()
  • .crs and .to_crs(...)
  • .map and .warp()
  • .proj and .reproject()

Answer: .crs and .to_crs(...). gdf.crs reports the projection; gdf.to_crs(...) reprojects to a different CRS.

Which method joins two layers based on their spatial relationship?

  • spatial_merge()
  • merge()
  • concat()
  • sjoin()

Answer: sjoin(). geopandas.sjoin (or gdf.sjoin) performs a spatial join using predicates like intersects or within.

Which common EPSG code represents WGS84 longitude/latitude?

  • EPSG:2154
  • EPSG:0000
  • EPSG:4326
  • EPSG:3857

Answer: EPSG:4326. EPSG:4326 is WGS84 lon/lat, the typical CRS for GPS coordinates and GeoJSON.

How do you quickly draw a map from a GeoDataFrame?

  • gdf.map_it()
  • gdf.plot()
  • gdf.draw()
  • gdf.render()

Answer: gdf.plot(). gdf.plot() renders the geometries with matplotlib, optionally colored by a column.

Why must two layers share a CRS before a spatial join?

  • So coordinates are comparable in the same reference system
  • To save memory
  • It is not required
  • For nicer colors

Answer: So coordinates are comparable in the same reference system. Spatial operations need both layers in the same CRS so their coordinates line up correctly.

Continue this course