首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >地图Folium Python

地图Folium Python
EN

Stack Overflow用户
提问于 2021-08-23 09:55:55
回答 1查看 143关注 0票数 0
代码语言:javascript
复制
import folium 
import pandas as pd

df_bedarf = pd.read_csv('C:/Users/xxxxx/Desktop/xxxxxx/xxxxxxx.csv', sep = ";")
df_bedarf.head()

df_locations = df_bedarf[["Latitude", "Longitude"]]
location_list = df_locations.values.tolist()
location_list_size= len(location_list)

map_points = folium.Map(location = [47.57087, 13.43828], zoom_start = 7)

for point in range(0, location_list_size):
    folium.circle(
        location = location_list[point],
        popup=df_locations["suburb"][point] + ": " + df_locations["Sort"][point],
        radius = str(df_locations["t/a"][point]*100)
        color="#17cbef",
        fill=True,
        opacity =0.8,
        fill_color="#17cbef,
        stroke = True, 
        weight = 1.0,
    ).add_to(map_points)
    
map_points

这是head():

代码语言:javascript
复制
    Unnamed: 0  Suburb  Sort    t/a     Latitude    Longitude
0   0   Wien    CC  2272    48.201900   16.370000
1   1   Graz    LD  426     47.079675   15.420325
2   2   Feldbach    LD  248     46.952187   15.888309
3   3   Zerlach     RE  2041    46.944865   15.650902
4   4   Gnas    SM  1488    46.874198   15.826138

我得到一个语法错误?

我的错误在哪里?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-23 13:14:49

造成此错误的原因可能是位置信息的纬度和经度不采用列表格式。使用df.itertools()更容易处理数据框架,所以我修改了代码。另外,通过适当添加一个新列来引用圆圈的大小,所以请修正这个问题。圆圈的颜色和透明度也已被修改,以使它们更容易定位。

代码语言:javascript
复制
import pandas as pd
import numpy as np
import io

data = '''
  Suburb  Sort    t/a     Latitude    Longitude
0   Wien    CC  2272    48.201900   16.370000
1   Graz    LD  426     47.079675   15.420325
2   Feldbach    LD  248     46.952187   15.888309
3   Zerlach     RE  2041    46.944865   15.650902
4   Gnas    SM  1488    46.874198   15.826138
'''

df_locations = pd.read_csv(io.StringIO(data), delim_whitespace=True)
df_locations['points'] = np.random.randint(100, 500, (5,))

import folium 

map_points = folium.Map(location=[47.210565, 15.8311348], zoom_start=7)

# for i in range(len(df_locations)):
for idx, row in df_locations.iterrows():
    folium.Circle(
        location=[row['Latitude'], row['Longitude']],
        popup=row["Suburb"] + ": " + str(row["Sort"]),
        radius = row['points']*100,
        color="#dc143c",
        fill=True,
        opacity=1.0,
        fill_color="#dc143c",
        stroke=True,
        weight=1.0,
    ).add_to(map_points)

map_points

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68890589

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档