Introduction to Geopandas


This guide will explain how to visualize data on a map using geopandas. We will be using Google Trend data on how often the people search for the weather forecast in different regions of Spain.

Please upvote if you like my work, and feel free to fork and extend my work :D

1. Libraries


First, I will install the libraries that are not pre-installed on the kyso workspaces:

  • geopandas
  • descartes
  • matplotlib.pyplot

2. Importing files


The source of my shape file is, which has a lot of different files, all open source:

I have a geojson file of the Spanish regions. I actually only need the 'texto' column, which includes all the region names, and the 'geometry' column, which will draw the area of each region.

Now, I import the data I want to represent in the geopandas map.

In this case, the data will show the popularity of the word 'meteosat' (the weather forecast in Spain) in the different regions of Spain. The data is gathered by Google Trends and the results show where in Spain is more popular to search for the weather forecast.

The file is called 'geoMap.csv'.

In this case, I need to rename the regions from my Google Trends file, where the regions are in english, and convert them into Spanish.

3. Merge files


I create a unique table of contents merging the two files' values.

The two files have a column in common, the name of the regions, which is how we merge the files. This is why I need to have the same spelling.

4. Create geopandas map


Let's start with the fun part.

Now that the files are merged I start setting some values for the map before creating the map.

Those values are simple, like max and min values, title of the graph, if we want an axis label or not, text that we want to appear on each section or region, etc.

Note: Geopandas creates a map proportional so all areas will be represented on the visualization. For this case, sorry but, I need to delete some regions in Spain (the Canary and Baleares island and the cities Ceuta and Melillar) because the map looks nicer without them.

Canary (28° 6' N, 15° 26' W) is located next to the south-west of Morocco.

I set the min-max value to 0-100 because the Google Trend has a max value of 100, for the regions where people search more for their forecast, and a min val of 0, for those regions where searching for the forecast is really unpopular.

Loading output library...
Loading output library...

And there it is! :D

A map with the Spanish regions showing the regions where searching for the weather forecast is more popular.

I hope you enjoyed this short guide, and please leave a comment if you want to suggest anything or make a tip.