Type error: cannot convert the series to

The problem is quite trivial,

  1. You’re using a Pandas.DataFrame. Now when you slice it rep_points['lat'], you get a Pandas.Series.
  2. The gmplot.scatter() is expecting an iterable of floats not a series of floats.
  3. Now if you convert your Pandas.Series to a list by using rep_points['lat'].tolist() It’ll start working

Below is your updated code:

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:

  1. type(rep_points['lat']) is a Pandas.Series
  2. type(rep_points['lat'][0]) is a Numpy.Float
  3. to iterate over a Pandas.Series you need to use iteritems

Leave a Comment