我的代码失败,并显示“ValueError:直接添加到地图时必须分配标记位置。”,我不太明白为什么或如何修复它
我正在使用SpaceX数据集在forium上进行启动站点位置分析,并且我正在尝试创建标记簇,因为它们是简化包含许多具有相同坐标标记的地图的好方法。我创建了一个标记群集对象,并为启动结果分配了颜色。
另外,我的数据帧中唯一的列是:“启动站点”,“ lat”,“ long”,“ class”和“ marker_color”。
现在,问题是:“对于SpaceX_DF数据框中的每一行,使用其坐标创建标记对象,并自定义标记的图标属性以指示此启动是成功还是失败”。
我的代码:
import folium
import wget
import pandas as pd
from folium.plugins import MarkerCluster
from folium.plugins import MousePosition
from folium.features import DivIcon
def assign_marker_color(launch_outcome):
if launch_outcome == 1:
return 'green'
else:
return 'red'
spacex_csv_file = wget.download('https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-DS0321EN-SkillsNetwork/datasets/spacex_launch_geo.csv')
spacex_df = pd.read_csv(spacex_csv_file)
spacex_df = spacex_df[['Launch Site', 'Lat', 'Long', 'class']]
launch_sites_df = spacex_df.groupby(['Launch Site'], as_index=False).first()
launch_sites_df = launch_sites_df[['Launch Site', 'Lat', 'Long']]
marker_cluster = MarkerCluster()
spacex_df['marker_color'] = spacex_df['class'].apply(assign_marker_color)
spacex_df.tail(10)
site_map.add_child(marker_cluster)
for index, record in spacex_df.iterrows():
marker = folium.Marker(location = [record['Lat'], record['Long']],icon=folium.Icon(color='white',icon_color=record['marker_color'])).add_to(marker_cluster)
marker_cluster.add_child(marker)
site_map
我尝试创建一个称为坐标的变量,可以在其中存储DF的纬度和经度列,然后将坐标值保存到folium.marker()中所需的位置参数(),但甚至不行。我有点困惑,会喜欢任何类型的帮助!
再次,我的错误消息是:“ valueError:标记位置必须直接添加到映射中。
I am working on Launch Sites Locations Analysis with Folium using a spaceX dataset, and I am trying to create Marker Clusters, because they are good way to simplify a map containing many markers having the same coordinate. I created a Marker Cluster Object and assigned a color to launch outcomes.
Also, the only columns in my dataframe right now are: "Launch Site", "Lat", "Long", "Class", and "marker_color".
Now, the question is: "for each row in spacex_df data frame, create a Marker object with its coordinate, and customize the Marker's icon property to indicate if this launch was a success or fail".
My Code:
import folium
import wget
import pandas as pd
from folium.plugins import MarkerCluster
from folium.plugins import MousePosition
from folium.features import DivIcon
def assign_marker_color(launch_outcome):
if launch_outcome == 1:
return 'green'
else:
return 'red'
spacex_csv_file = wget.download('https://cf-courses-data.s3.us.cloud-object-storage.appdomain.cloud/IBM-DS0321EN-SkillsNetwork/datasets/spacex_launch_geo.csv')
spacex_df = pd.read_csv(spacex_csv_file)
spacex_df = spacex_df[['Launch Site', 'Lat', 'Long', 'class']]
launch_sites_df = spacex_df.groupby(['Launch Site'], as_index=False).first()
launch_sites_df = launch_sites_df[['Launch Site', 'Lat', 'Long']]
marker_cluster = MarkerCluster()
spacex_df['marker_color'] = spacex_df['class'].apply(assign_marker_color)
spacex_df.tail(10)
site_map.add_child(marker_cluster)
for index, record in spacex_df.iterrows():
marker = folium.Marker(location = [record['Lat'], record['Long']],icon=folium.Icon(color='white',icon_color=record['marker_color'])).add_to(marker_cluster)
marker_cluster.add_child(marker)
site_map
I have tried creating a variable called coordinates, where I can store the latitude and longitude columns of the df, then save that coordinates value to the location parameter necessary in folium.Marker(), but not even that worked. I am a little confused and would love any type of help!
Once again, my error message is, "ValueError: Marker location must be assigned when added directly to map. <folium.folium.Map at 0x7f11f92cd310>".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论