Because the choropleth is based on the aggregated counts, the speed isn't suffering from large datasets. Note that I used the whole dataset instead of the 1000 records used earlier. The additional Python code to create a choropleth is as follows. Save the result as sfpddistricts.geojson and upload the file to your Domino project.
#Python map zip file
Select the downloaded zip file and put crs:84 in the Target SRS field. The easiest way is to use an ogr2ogr web client. The next step is to convert the Shapefile into a geojson file. With a Google search on "sfpd districts geojson" I found a government open data website with a Shapefile that almost matches my needs. To create a choropleth, we need a geojson file to create the areas/boundaries that match the San Francisco police districts in the data file. Lucky for us, there is also a way to create a choropleth map thanks to Folium.Ī choropleth map (from Greek χώρο ("area/region") + πλήθος ("multitude")) is a thematic map in which areas are shaded or patterned in proportion to the measurement of the statistical variable being displayed on the map, such as population density or per-capita income.
Well, that was fun! But this might not be an ideal visualization to compare maps with each other. You save a map as an html file by using map.create_map(path='map.html') instead of display(map) Choropleth Map Folium can be used with other tilesets like Mapbox or Cloudmade too. The tileset used in here is OpenStreetMap (which is default). When running this, it creates a map with location markers that are clustered ( clustered_marker = True) if close together. # add a marker for every record in the filtered data, use a clustered viewįor each in errows(): _map = folium.Map(location=SF_COORDINATES, zoom_start= 12) # create empty map zoomed in on San Francisco import foliumĬrimedata = pd.read_csv( "SFPD_Incidents_2015.csv") It loads the incident file into a pandas dataframe, selects the first 1000 records to speed things up, and creates an inline map containing an interactive map with markers based on the resulting dataset. The Jupyter notebook contains only a few lines of code.
#Python map install
To begin set up, you will want to install Folium by running pip install folium in your terminal. With the data installed, we can begin writing the script to visualize our data. Use the Export function (select csv) to download the entire dataset. I decided to use SFPD incident data from SF OpenData. Collecting the Dataįor this example I needed some interesting data that contains locations.
#Python map how to
This Jupyter example shows how to display maps inline. In case you use Jupyter (like myself), you might prefer to get inline maps.
The Folium github contains many other examples.īy default, Folium creates a map in a separate HTML file. To get an idea, just zoom/click around on the next map to get an impression. The fact that the Folium results are interactive makes this library very useful for dashboard building. What is Folium?įolium is a powerful Python library that helps you create several types of Leaflet maps. I then describe a how to use Domino to turn this Python code into a self-service reporting tool. This blog post outlines how I used Folium to visualize a data set about crime in San Francisco. After some research I discovered Folium, which makes it easy to create Leaflet maps in Python. But when it comes to creating maps in Python, I have struggled to find the right library in the ever changing jungle of Python libraries.