我有一个包含位置的geojson文件。其中“parking”:始终为0。你知道吗
'type': 'Feature',
'properties': {
...// Other fields
'latitude': -74.0121613846062,
'longitude': 40.7043040747924,
'parking': 0 }
我想从另一个csv文件数据集更新它。你知道吗
-------------------------------------------
latitude + Longitude + Possible_parking
-------------------------------------------
-74.012161 40.804 -1
-1:无法停车
1:可能停车
我想更新geojson文件。你知道吗
data = pd.read_csv("data/_all.csv")
geojson_in = open('data/input.json', 'r')
tracts_geojson = json.load(geojson_in)
geojson_in.close()
# For each record in the geojson file, add location information
for i, r in enumerate(tracts_geojson['features']):
for x in range(len(data.latitude.values)):
if ((r['properties']['latitude']==data["latitude"][x]) and (r['properties']['longitude']== data["longitude"][x])):
r['properties']['parking'] = str(data['Possible_parking'][x])
我使用的脚本的问题是,它需要很长的时间(+现在24小时)。 我不想把csv文件直接转换成json,因为输入.json包含CSV文件中找不到的其他信息。你知道吗
有没有什么方法能让你更快?你知道吗
对于JSON文件中的每个功能,您将遍历整个停车场CSV行;这是一个N*M循环;一个600MB CSV文件包含大约3000万个停车位条目(每行大约21个字节),并且您将遍历每个功能的所有3000万个。你知道吗
要将整个CSV文件加载到字典中:
对于每个JSON条目,使用此选项而不是在整个数据集上循环:
字典中的查找需要固定的时间;而不是每个特性使用3000万个循环,而是每个特性使用一个直接的查找。你知道吗
相关问题 更多 >
编程相关推荐