ValueError求助:Geopandas中无法将格式错误的坐标字符串转为浮点数
ValueError求助:Geopandas中无法将格式错误的坐标字符串转为浮点数
我正在处理地理空间数据,尝试用机器学习做预测。以下是我读取数据的代码:
import geopandas as gpd import fiona from fiona.drvsupport import supported_drivers supported_drivers['CSV'] = 'csv' all_data = gpd.read_file('book3.csv')[['Name','description', 'geometry']]
数据样本:
Name description geometry 0 0 mall POLYGON Z((76.4805522843099,76.4905522843099)) 1 1 Restaurants POLYGON Z((76.0253377024336,76.0255777024336 2 2 High Fashion POLYGON Z((76.4805522843097,76.1253377024336)) 3 3 Supermarket POLYGON Z((76.4825679653146,76.4825681653146)) 4 4 Cheap Fashion POLYGON Z((76.5136851191604,76.6136851191604) 5 5 Cosmetics POLYGON Z((76.5486903603254, 76.7126903603254)) 6 6 Electronic POLYGON Z((76.5442602768404,76.7112602768404)) 7 7 West Wing POLYGON Z((76.4984018904527,76.4987348904527)) 8 8 Brought Yes LINESTRINGZ(76.4984018.904527.00000,76.4987348... 9 9 Brought Yes LINESTRINGZ(76.4984018.904527.00000,76.4987348... 10 10 Brought Yes LINESTRINGZ(76.4984018.904527.00000,76.4987348... 11 11 Brought Yes LINESTRINGZ(76.5486903.603254.00000,76.7126903... 12 12 Brought Yes LINESTRINGZ(76.5442602.768404.00000,76.7112602... 13 13 Brought Yes LINESTRINGZ(76.5442602.768404.00000,76.7112602... 14 14 Brought Yes LINESTRINGZ(76.4984018.904527.00000,76.4987348... 15 15 Brought Yes LINESTRINGZ(76.4984018.904527.00000,76.4987348... 16 16 Brought Yes LINESTRINGZ(76.5486903.603254.00000,76.7126903... 17 17 Brought Yes LINESTRINGZ(76.5486903.603258.00000,76.7126903... 18 18 Brought No LINESTRINGZ(76.4984018.904545.00000,76.4987348... 19 19 Brought No LINESTRINGZ(76.5486903.603265.00000,76.7126903... 20 20 Brought No LINESTRINGZ(76.5486903.603254.00000,76.7126903... 21 21 Brought No LINESTRINGZ(76.5486903.603255.00000,76.7126903... 22 22 Brought No LINESTRINGZ(76.5486903.603254.00000,76.7126903...
我尝试通过以下方式将几何数据转为浮点数:
import pandas as pd from shapely.geometry.point import Point results = [] # split the lines into points for i, row in itineraries.iterrows(): # print(row) #removing redundant information list_of_points_extracted = str(row['geometry']).strip('LINESTRINGZ(').strip(')').strip().split(',') list_of_points_extracted = [point[:-2] for point in list_of_points_extracted] # print(list_of_points_extracted) # convert lat and long into floats for x in list_of_points_extracted: for y in x.rstrip(' ').rstrip().split(','): print((float(y).type))
但是我遇到了如下错误:
value error: could not convert string to float: '76.4984018.904527.000'
我尝试了很多方法都没成功,恳请大家帮帮我,谢谢!
备注:内容来源于stack exchange,提问作者TinaTz
相关产品推荐
相关产品推荐

