我正在为我的地图创建字典,以按销售地区地图的经度和纬度汇总所有县/州,但是它不会停止运行,尽管我昨晚尝试过并且效果很好。
我已经重新启动了几次。
Territory1 = ["Austin","Bay Area - SF","Bay Area - SV","Bold North","Chicago 1","Chicago 2","Dallas 1","Dallas 2","Desert","Georgia","Great Lakes","LA","LA 2","Maryland Metro","Metro Central","Metro East","Mid South","Mid-Atlantic","Missouri Valley","New England 1","New England 2","NY Metro","OC/LA","Ohio Valley","Peninsula","Philly East","Philly West","PNW 1","PNW 2","PNW 3","Rockies","So Cal","South","SoVA"]
for territory in Territory1:
territory_data = dict(
lat = df.loc[df["Territory1"]==territory,"Lat"],
lon = df.loc[df["Territory1"]==territory,"Lon"],
name = territory,
marker = dict(size = 8, opacity = 0.5),
type = 'scattermapbox')
Territory1.append(territory_data)
我想要的是一个聚合列表,该列表将显示在地图上,用户可以单击该列表以单独查看每个区域(这些区域如Territory1列表中所列)。
答案 0 :(得分:3)
它不会停止,因为:
Territory1.append(territory_data)
在Territory1
列表中添加新元素,然后
for territory in Territory1:
没有结束。
可能您需要:results_list.append(territory_data)
答案 1 :(得分:0)
正如@serafeim所说,您要在添加列表的同时对其进行遍历。
Territory1 = ["Austin","Bay Area - SF","Bay Area - SV","Bold North","Chicago 1","Chicago 2","Dallas 1","Dallas 2","Desert","Georgia","Great Lakes","LA","LA 2","Maryland Metro","Metro Central","Metro East","Mid South","Mid-Atlantic","Missouri Valley","New England 1","New England 2","NY Metro","OC/LA","Ohio Valley","Peninsula","Philly East","Philly West","PNW 1","PNW 2","PNW 3","Rockies","So Cal","South","SoVA"]
for territory in Territory1:
territory_data = dict(
lat = df.loc[df["Territory1"]==territory,"Lat"],
lon = df.loc[df["Territory1"]==territory,"Lon"],
name = territory,
marker = dict(size = 8, opacity = 0.5),
type = 'scattermapbox')
Territory1.append(territory_data)
我相信您想要做的是:
territory_dicts = {}
for territory in Territory1:
temp_dict = dict(lat: df.loc[df["Territory1"]==territory,"Lat"],
lon: df.loc[df["Territory1"]==territory,"Lon"],
name: territory,
marker: dict(size = 8, opacity = 0.5),
type: 'scattermapbox')
territory_dicts[territory] = temp_dict