简体   繁体   English

使用 Pandas & Folium 在地图上绘制标记

[英]Plotting markers on a map using Pandas & Folium

I am trying to plot a large number (~20,000) of circle markers using Folium.我正在尝试使用 Folium 绘制大量(~20,000)圆形标记。 The latitude and longitude data is contained in a Pandas DataFrame (within "LAT" and "LONG" columns).纬度和经度数据包含在 Pandas DataFrame 中(在“LAT”和“LONG”列中)。 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.同时,我不必使用 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.如果您知道有更合适的工具(尽管我仍然需要将数据保存在 Pandas DataFrame 中),请告诉我。

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:沿列轴使用 apply:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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