Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting markers on a map using Pandas & Folium

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
like image 281
marillion Avatar asked Oct 30 '16 23:10

marillion


People also ask

How do I add a marker to a pandas map?

Let's create a Pandas dataframe. It provides a numeric value for a few big cities, along with their geographic coordinates Now, loop through this dataframe, and add a marker to each location thanks to the Marker () function: # add marker one by one on the map for i in range(0,len( data)): folium.

How do I add markers to a Dataframe in Python?

It provides a numeric value for a few big cities, along with their geographic coordinates Now, loop through this dataframe, and add a marker to each location thanks to the Marker () function: # add marker one by one on the map for i in range(0,len( data)): folium.

What are the best tools for plotting in geopandas?

2. Plotting With GeoPandas 3. Choropleth Maps 4. Scatter Plots on Maps Geopandas provides easy to use interface which lets us work with geospatial data and visualize it. It lets us create high-quality static map plots.

How can I plot my geographic data?

Say you have geographic data you want to plot; you could use a bar graph with country names and plot your data as a bar, but that’s boring. A more visually appealing way of presenting the data would be to overlay it on a map to physically show how your data interacts. This can be a challenging endeavor, but I’m here to help.


1 Answers

Use apply along the column axis:

df.apply(lambda row:folium.CircleMarker(location=[row["LAT"], 
                                                  row["LONG"]]).add_to(map_osm),
         axis=1)
like image 148
Zeugma Avatar answered Oct 31 '22 08:10

Zeugma