【问题标题】:Reading a value from csv file dash python从csv文件破折号python中读取一个值
【发布时间】:2019-02-07 06:54:56
【问题描述】:

我在 (123.456,789.1234) 之类的 csv 文件中有值 map_geo_location,如何获取破折号中的值以将其添加为属性的值 lanlat 在 python 中地理分散破折号?

【问题讨论】:

  • 我想用它来显示基于值(123.456,789.1234)的地图位置,所以我希望它为 lan=123.456 , lat=789.1234
  • 看看下面发布的答案是否有帮助?

标签: python python-3.x geopandas plotly-dash


【解决方案1】:

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)

然后:

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

输出:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多