Search code examples
pythonpython-3.xgeopandasplotly-dash

Reading a value from csv file dash python


I have value map_geo_location in csv file like (123.456,789.1234) , How can I get the value in dash to add it as the values for the attributes lan and lat geo scattered dash in python?


Solution

  • list.txt:

    (123.456,789.1234)
    (763.426,659.9834)
    (873.566,789.6734)
    (773.766,239.234)
    (343.776,889.1344)
    (873.766,679.1344)
    

    and then:

    logFile = "list.txt"
    with open(logFile) as f:
        content = f.readlines()
    
    # you may also want to remove empty lines
    content = [l.strip() for l in content if l.strip()]
    
    lat = []
    long = []
    
    for line in content:
        lat.append(line.rpartition(',')[2].strip(")"))
        long.append(line.rpartition(',')[0].strip("("))
    
    
    print("Latitude List: {}".format(lat))
    print("Longitude List: {}".format(long))
    

    OUTPUT:

    Latitude List: ['789.1234', '659.9834', '789.6734', '239.234', '889.1344', '679.1344']
    Longitude List: ['123.456', '763.426', '873.566', '773.766', '343.776', '873.766']