I’ve always had a fondness for maps; you can find them in various boxes, in books as book-markers, stuffed away within old piles of bills and such heavily stained with mug rings and disuse. Not sure why I continue to keep them. I think what it really comes down to is that its such a uniquely powerful way of displaying information about the world, all the while providing context for other bits of information about the world. Any map at all is just a really beautiful way (in my opinion, at least) of providing conteet to information.

Basically, what I’m saying is, this ain’t the last time you’ll be seeing a map on this blog!

The Folium Library

While I’ve been familiar with the mapping industry in various contexts for a while, I haven’t really taken the dive of merging my love of maps with my love of data science. However, I recently discovered the Folium library, and it is incredible!!!

Here’s all the code you need to generate a beautiful, interactive html map in Python. Well, not all the code. But you get the idea. Down the road I’ll go over some of the more interesting things that an be done using Folium, so stay tuned.

# This creates the map object
m = folium.Map(
    location=[37.541, 126.981], # center of where the map initializes
    tiles='Stamen Toner', # the style used for the map (defaults to OSM)
    zoom_start=12) # the initial zoom level

# Diplay the map
m

That’s it! Nice and simple…for now.

Here’s a breakdown of whats going on in the code snippet above:

  • location: simple enough, these are gps coordinates used to center the map. You can find these on Google Maps fairly easily.
  • tiles: this describes the style of the map itself (the graphic representation of the map is handled using square image tiles that are loaded based on the {x, y, z} coordinates)
  • zoom_start: how zoom-ed in do you want to be?
  • m: displays the map

The Map Itself

Here’s the map I made that simply displays a pin for each location in Seoul describing the pollutant measurements. In the upper right you can control which pollutants are displayed, and of course its fully interactive, meaning you can pan around, zoom in and out, etc. This map was originally part of a Kaggle notebook, and the data for the pollution measurements was compiled and provided by bappe on the Kaggle site.

That’s all on I have on exploring Folium for now; check back for new posts on other fun features like heatmaps!!