Plotting markers on a map using Pandas & Folium

data-visualization, folium, pandas, python

Solution

Use apply along the column axis:

df.apply(lambda row:folium.CircleMarker(location=[row["LAT"], 
                                                  row["LONG"]]).add_to(map_osm),
         axis=1)

Problem

I am trying to plot a large number (~20,000) of circle markers using Folium. The latitude and longitude data is contained in a Pandas DataFrame (within "LAT" and "LONG" columns). I have come up with the following (inefficient) code, which requires iterating through the dataframe row by row. Not surprisingly, it takes quite a while to plot the map. Is there a better/faster way to accomplish this? Meanwhile, I do not have to use Folium. If there is a more suitable tool that you know of (I still have to keep the data in a Pandas DataFrame though), please let me know. Thanks! ``` map_osm = folium.Map(location=[43.094768, -75.348634]) for index, row in df.iterrows(): folium.CircleMarker(location=[row["LAT"], row["LONG"]]).add_to(map_osm) map_osm ```

Original source