Sunday 3:00 PM–3:45 PM in Visualization - Room 100D/E

Beautiful, Interactive, and Portable Maps using Folium and Live API Data

Ariel M'ndange-Pfupfu

Audience level:
Intermediate

Description

Leaflet.js, a JavaScript visualization library, makes maps that are as lightweight and flexible as they are interactive and web-friendly. Folium brings that capability to Python, so we can use our favorite tools to ingest, join and process location data from the Census, WMATA, and Walkscore APIs and end up with HTML/JS maps that can be rendered in a notebook or served programmatically via web app.

Abstract

Motivation

Maps are a common and universally-recognized way of accessing and thinking about the spatial aspects of data. They are also an interesting mixture of form and function. They need to be useful and easy to parse, but they can also be beautiful, and the best ones are both. There's a similar trade off in visualization tools: Some are practical and good for exploring data, and others are focused on presentation and the viewer experience. Leaflet.js is an open source JavaScript mapping library that handles both aspects well, allowing for fast and easy experimentation as well as a beautiful, interactive result that's web and mobile ready. Folium is a Python wrapper for Leaflet, and allows us to integrate these maps into the PyData stack, and ultimately create them on-demand in a web application.

Objective

We'll walk through an example using live data from the Census, WMATA (DC public transit), and Walkscore, to explore different ways we can look at a city through its geospatial data. Starting from the public source data, to the local cache, Python data manipulation, Folium mapping, and Flask deployment, you should come away with a general idea of how the pieces fit together. The talk will be presented using Jupyter Lab, and a GitHub repo will be provided so you can recreate the environment, follow along, and then mess around with the details later. That being said, there are no advanced concepts in the talk, and you can treat it as a proof of concept without worrying too much about the implementation.

Target Audience

You'll get the most out of this talk if you have a solid understanding of:

Content

Live Bus Tracker (15 min)

We'll create a simple representation of where buses are in real time.

Folium

We'll explore the basics of the Folium API:

APIs

We'll cover the basics of API interaction, using the requests package to make the calls and ediblepickle to cache the information - after all, we'd never hit a free API more than we had to.

Layering Population and Income (5 min)

We'll use Folium choropleths to represent data broken down into regions in the GeoJSON format. We'll use colormaps and pandas to process the data beforehand.

Overlaying Walkscore (5 min)

We'll join the public transit data with Walkscore information to demonstrate how we can use Python to formulate the inputs to an API call from the outputs of a previous call. Then, we demonstrate how you might represent that lens on the map.

Deploying to the Web (5 min, leave details for questions)

We show how the bus tracker can be wrapped up into a Flask application and deployed using Heroku, so you can try this at home!

Subscribe to Receive PyData Updates

Subscribe