I am using pandas, and folium to replicate the following example, but with my CSV data to produce a heat map.

Here's what my data looks like:


and here is the code I am using currently:

import pandas as pd
import numpy as np
import folium.plugins as plugins  
from datetime import datetime, timedelta

    data = [(df3).tolist() for i in range(100)]

    m = folium.Map([40., -73.], tiles='stamentoner', zoom_start=6)

    hm = plugins.HeatMapWithTime(


The example works, but I cannot input my own data, as it results in errors. Would anyone know how to plot the X, and Y data from my CSV or an approach to get me started to produce a heatmap?

  • 1
    You should post an extract of the python code you are using, it would be easier to see what's the problem...Seems the "data" is a numpy array ?
    – gisnside
    Dec 4, 2017 at 22:47
  • @gisnside Thank you for your response and sorry about that, I've updated my question, but yes it is currently a numpy. I'm trying to input my CSV data instead of random points in the NP array. Any clue on how to approach this? Dec 5, 2017 at 15:47
  • You can start importing your data in panda with df = pd.read_csv(file_csv) (see réf. pandas.pydata.org/pandas-docs/stable/generated/…). To convert a pandas dataframe (df) to a numpy ndarray, use this code: df=df.values df now becomes a numpy ndarray. Have a try getting this done, edit your code, then we will see what's the problem with folium ;)
    – gisnside
    Dec 5, 2017 at 16:54
  • @gisnside Thank you, I was able to plot a successful heatmap, but I would like to take it a step further in integrating time. So now I have a list of coordinates df3 and a list of dates in mm/dd/yyyy format. How would I go about displaying the heat map based on the time? Dec 6, 2017 at 18:59
  • I posted an answer so it's more visible than in the comments. However, i don't have yet the answer for the time.
    – gisnside
    Dec 6, 2017 at 21:45

1 Answer 1


You can start importing your csv data (file_csv) in panda in a dataframe (df) with a code like :

import pandas as pd

df = pd.read_csv(file_csv) 

(see réf. https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html).

To convert a pandas dataframe (df) to a numpy ndarray, use this code:


df now becomes a numpy ndarray.

For the time, there's some documentation in the heat_map_with_time.py script. I have to look further (Ref. https://github.com/python-visualization/folium/blob/master/folium/plugins/heat_map_withtime.py)

Form the class infos:

index: Index giving the label (or timestamp) of the elements of data. Should have the same length as data, or is replaced by a simple count if not specified.

From what i understand, you need to have a time index dataframe the same size as the data dataframe (or array)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.