我有一个 600万行的csv ,我需要将其转换为 geojson 文件。
云解决方案存在于Internet中,但要花费一整天的时间进行转换。
有没有一种快速的方法可以使用python做到这一点?
问题更新:
我尝试了解决方法here,但出现此错误:
ValueError Traceback (most recent call last)
<ipython-input-48-0224e45ed66e> in <module>()
5 with open('Documents/neo4j-community-3.3.5/import/train.csv', newline='') as csvfile:
6 reader = csv.reader(csvfile, delimiter=',')
----> 7 for pickup_latitude, pickup_longitude in reader:
8 pickup_latitude,pickup_longitude = map(float, (pickup_latitude, pickup_longitude))
9 features.append(
ValueError: too many values to unpack (expected 2)
这是我的代码:
import csv, json
from geojson import Feature, FeatureCollection, Point
features = []
with open('Documents/neo4j-community-3.3.5/import/train.csv', newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',')
for pickup_latitude, pickup_longitude in reader:
pickup_latitude,pickup_longitude = map(float, (pickup_latitude, pickup_longitude))
features.append(
Feature(
geometry = Point((pickup_longitude, pickup_latitude)),
)
)
collection = FeatureCollection(features)
with open("GeoObs.json", "w") as f:
f.write('%s' % collection)
注意:pickup_latitude和Pickup_longitude是我的csv中的两列
答案 0 :(得分:1)
该错误意味着csv文件中的列多于for
语句期望的两列。要解决此问题,您可以采用所有列,然后仅分析前两列:
for cols in reader:
pickup_latitude, pickup_longitude = map(float, cols[0:2])