地图 Folium Python

Maps Folium Python

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():

    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

我收到语法错误???

我的错误在哪里?

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

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