Python合二为一唱歌

2024-05-23 13:50:59 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建折线对叶地图。为此,它需要一组坐标作为列表

它读取以下[[]]之间的一组坐标作为一组GPS坐标

进口叶

coordinates = [[42.408485,-83.4551716666667],[42.408485,-83.45517],
               [42.408485,-83.45516],[42.4084866666667,-83.4551416666667]], 
               [[42.4085016666667,-83.4547916666667],[42.4085016666667,-83.45479],[42.4085033333333,-83.4547533333333]]
# Create the map and add the line
m = folium.Map(location=[41.9, -97.3], zoom_start=4)
my_PolyLine=folium.PolyLine(locations=coordinates,weight=5)
map_US.add_children(my_PolyLine)

我有一个巨大的文件,我正试图实现同样的从文件

id  long    lat
a   -84.52694   46.931625
a   -84.52684   46.931725
a   -94.25526333    42.71689167
a   -94.25524667    42.71689333
a   -94.25519167    42.716895
a   -94.25505167    42.71690833
b   -94.25531167    42.71687167
b   -94.255205  42.71689
b   -94.25515   42.7169
b   -94.25507   42.71691167
b   -94.25507167    42.71691167
b   -94.25511   42.716905
b   -94.25514667    42.71689833
b   -94.25515667    42.71689667
b   -94.255165  42.716895
b   -94.25518167    42.71689
c   -94.25519167    42.71688833
c   -94.25522833    42.71688167
c   -94.25523833    42.71688
c   -94.25525   42.71688

所有的GPS坐标都要形成一个列表并按id列分组,我的代码如下所示

import numpy as np
import folium
from folium import plugins
import pandas as pd
from folium.plugins import HeatMapWithTime
df_acc= pd.read_csv(f)
df_acc['lat_long'] = [', '.join(str(x) for x in y) for y in map(tuple, df_acc[['lat', 'long']].values)]
a=list(df_acc['lat_long'].head(10))
m = folium.Map(location=[41.9, -97.3], zoom_start=4)
my_PolyLine=folium.PolyLine(locations=a,weight=5)
m.add_children(my_PolyLine)
m

这并没有给出任何结果,我如何才能将括号添加到列“a”中,并且仍然将其显示为float或list


Tags: theimportaddmapdf列表mylong