类型错误:无法将系列转换为< class'float'>

编程入门 行业动态 更新时间:2024-10-28 16:24:43
本文介绍了类型错误:无法将系列转换为< 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

以上是一个数据帧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)

但是效果不佳

推荐答案

问题很简单,

  • 您正在使用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
  • 下面是您的更新代码:

    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:

  • 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
  • 更多推荐

    类型错误:无法将系列转换为&lt; class'float'&gt;

    本文发布于:2023-11-07 07:02:18,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1565835.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:转换为   错误   类型   系列   amp

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!