Joining a shapefile attribute table to a CSV file

Joining attribute tables to other database tables allows you to use a spatial data set to reference a dataset without any geometry, using a common key between the data tables. A very common use case for this is to join a vector dataset of census attributes to a more detailed census attribute dataset. That is the use case we will demonstrate here by linking a US census track file to a detailed Comma Separated Value (CSV) file containing more in-depth information.

Getting ready

For this recipe you will need a census tract shapefile and a CSV file containing the appropriate census data for the shapefile. You can download the sample dataset from the following URL:

https://github.com/GeospatialPython/Learn/raw/master/census.zip ...

Get QGIS Python Programming Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.