Folium is an easy to use Python GIS tool
Jul 28, 2017 · 2 min read
My GIS needs tend to be fairly basic. Most of the time I just want to see my data on a map, and I want it to be a painless part of my workflow. Folium fits the bill quite nicely.
I’ve only used folium for a couple of months now, but so far I have been very impressed. It’s a Python interface to the popular Leaflet.js library. Although it doesn’t expose all of Leaflet’s API, it’s been adequate for me. Speaking of APIs, it’s got a great one. Extremely easy to pick up. I’m looking forward to using folium some more and watching this project grow.
Here’s a simple example of mapping some points from a Pandas DataFrame
import pandas as pd
import folium#zip file from the census site
file_url = 'http://www2.census.gov/geo/docs/maps-data/data/gazetteer/2016_Gazetteer/2016_Gaz_zcta_national.zip'#Pandas usually infers zips as numerics, but we lose our leading zeroes so let's go with the object dtype
df = pd.read_csv(file_url, sep='\t', dtype={'GEOID' : object})#some column names have some extra padding
df.columns = df.columns.str.strip()
df.head()

#grab a random sample from df
subset_of_df = df.sample(n=100)#creating a map that's centered and zoomed in on our sample
some_map = folium.Map(location=[subset_of_df['INTPTLAT'].mean(),
subset_of_df['INTPTLONG'].mean()],
zoom_start=4)#creating a Marker for each point in df_sample. Each point will get a popup with their zip
for row in subset_of_df.itertuples():
some_map.add_child(folium.Marker(location=[row.INTPTLAT, row.INTPTLONG], popup=row.GEOID))
some_map

You can find the code here
