Aka*_*haC 2 python google-maps python-3.x pandas
lat long time
0 39.991861 116.344372 2.823611
1 39.979768 116.310597 22.263056
2 31.235001 121.470624 13.141667
3 31.248822 121.460637 1.805278
Run Code Online (Sandbox Code Playgroud)
上面是一个数据帧 rep_points。当我运行下面的代码时,它给出了一个错误
Type error: cannot convert the series to <class 'float'>
Run Code Online (Sandbox Code Playgroud)
在圆圈所在的那一行。
gmap = gmplot.GoogleMapPlotter(rep_points['lat'][0], rep_points['long'][0], 11)
gmap.plot(df_min.lat, df_min.lng)
gmap.scatter(rep_points['lat'],rep_points['long'],c='aquamarine')
gmap.circle(rep_points['lat'],rep_points['long'], 100, color='yellow')
gmap.draw("user001_clus_time.html")
Run Code Online (Sandbox Code Playgroud)
我应该如何解决这个错误?我试过使用
rep_pints['lat'].astype(float)
Run Code Online (Sandbox Code Playgroud)
和
rep_pints['long'].astype(float)
Run Code Online (Sandbox Code Playgroud)
但效果不佳
问题很简单,
Pandas.DataFrame. 现在当你切片它时rep_points['lat'],你会得到一个Pandas.Series.gmplot.scatter()期待一个iterable的floats不是series的floats。Pandas.Series为 a它将开始工作listrep_points['lat'].tolist()以下是您更新的代码:
rep_points = pd.read_csv(r'C:\Users\carrot\Desktop\ss.csv', dtype=float)
latitude_collection = rep_points['lat'].tolist()
longitude_collection = rep_points['long'].tolist()
gmap = gmplot.GoogleMapPlotter(latitude_collection[0], longitude_collection[0], 11)
gmap.plot(min(latitude_collection), min(longitude_collection).lng)
gmap.scatter(latitude_collection,longitude_collection,c='aquamarine')
gmap.circle(latitude_collection,longitude_collection, 100, color='yellow')
gmap.draw("user001_clus_time.html")
Run Code Online (Sandbox Code Playgroud)
其他有助于指出这一点的事情:
type(rep_points['lat']) 是一个 Pandas.Seriestype(rep_points['lat'][0]) 是一个 Numpy.FloatPandas.Series你需要使用的iteritems| 归档时间: |
|
| 查看次数: |
14524 次 |
| 最近记录: |