[Python] ValueError: could not convert string to float: '76.4984018.904527.000':geopandas

Discussão em 'Python' iniciado por Stack, Março 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am working with geospatial data and attempting to apply machine learning for prediction. Here’s how I read my data:

    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']]


    results sample:

    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...


    I am trying to convert geometry data to float in the following way:

    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))


    But I am getting the following error message:

    value error: could not convert string to float: '76.4984018.904527.000'


    I tried so hard but failed, please I need your help on this. Thank you

    Continue reading...

Compartilhe esta Página