How to make a time lapse heat map with Folium using NYC Bike Share data

A tutorial for those interested in creating a time lapse heat map.

Justin Morgan Williams



This article is essentially a tutorial for people interested in utilizing the Folium package to construct a time lapse heat map within the Python/Pandas environment. That said, it does provide interesting insights on station locations and most active hours for utilizing bike shares. This could be valuable information in deciding upon the location of new bike share stations.

The Data

The data used for this tutorial was gathered from NYC DOT information page on Bicyclists. They update the page regularly with .CSV datasets for Citi Bike Bike Share Trip Histories. Each dataset includes:

  • Trip duration (seconds)
  • Start time/stop time (date and time)
  • Start and end station name, ID, latitude & longitude
  • Bike ID
  • User type (“Customer” = 24-hour or 7-day pass user; “Subscriber” = annual member)
  • Birth year
  • Gender (0=unknown; 1=male; 2=female)

However, for this exercise we will be concerned solely with start station coordinates and date time columns. The data is updated monthly, and I’ve constructed a web scraper to iteratively scrape the webpage and return the last month of data. I won’t go over that in detail here, but it is available for perusal in the Github repo for this project.

Where to begin?

As usual the first step is to import the necessary Python libraries. The Folium library brings Leaflet.js to Python, letting us create interactive maps with a few lines of code.

First thing to do is create a base map object in Folium. I created a custom function generateBaseMap so that we can create a new map object when needed. This can be accomplished with the following lines of code:



Justin Morgan Williams

Data scientist passionate about the intersectionality of sustainability and data.