本文介绍了类型错误:无法将系列转换为< class'float'>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
您正在使用Pandas.DataFrame.现在,当您将其切片rep_points['lat']时,您将得到一个Pandas.Series.
gmplot.scatter()期望floats的iterable而不是floats的series.
现在,如果您使用rep_points['lat'].tolist()将Pandas.Series转换为list,它将开始工作
You're using a Pandas.DataFrame. Now when you slice it rep_points['lat'], you get a Pandas.Series.
The gmplot.scatter() is expecting an iterable of floats not a series of floats.
Now if you convert your Pandas.Series to a list by using rep_points['lat'].tolist() It'll start working
type(rep_points['lat'])是Pandas.Series
type(rep_points['lat'][0])是Numpy.Float
要遍历Pandas.Series,您需要使用iteritems
type(rep_points['lat']) is a Pandas.Series
type(rep_points['lat'][0]) is a Numpy.Float
to iterate over a Pandas.Series you need to use iteritems
以上是一个数据帧rep_points.当我运行下面的代码时,它给出了错误
The above is a dataframe rep_points. When i run the code below, it gives an error
Type error: cannot convert the series to <class 'float'>在做圆的行中.
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")我应如何解决此错误?香港专业教育学院尝试使用
How should i resolve this error? Ive tried using
rep_pints['lat'].astype(float)和
rep_pints['long'].astype(float)但是效果不佳
推荐答案问题很简单,
下面是您的更新代码:
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")其他有助于指出这一点的东西:
Other things that helped to point it out:
更多推荐
类型错误:无法将系列转换为< class'float'>
发布评论