简体   繁体   中英

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

Use apply along the column axis:

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

use this example, I hope this help!

#Create the Map
map_osm = folium.Map(
    location = [43.094768, -75.348634],
    zoom_start = 6
)
map_osm
#You Markler the point in Map
for indice, row in df.iterrows():
    folium.Marker(
        location=[row["LAT"], row["LONG"]],
        popup=row['NAME_COLUM'],
        icon=folium.map.Icon(color='yellow')
    ).add_to(map_osm)
map_osm

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM