我了解如何遍历单个列表和单个数组。但是,我有一个嵌套列表,并希望在[[same索引中的每个嵌套列表中的第一个元素后附加lon
,然后再移至下一个索引并重复该过程,直到已应用所有索引为止。
0 [[[-105.077274, 40.514625], [-105.077005, 40.5...
1 [[[-105.024284, 40.509791], [-105.024274, 40.5...
2 [[[-105.087928, 40.578187], [-105.087939, 40.5...
3 [[[-105.11976, 40.589318], [-105.11977, 40.587...
4 [[[-105.083718, 40.568761], [-105.08459, 40.56...
...
995 [[[-105.05362, 40.525161], [-105.053607, 40.52...
996 [[[-105.030003, 40.62114], [-105.030012, 40.62...
997 [[[-105.123316, 40.560645], [-105.123353, 40.5...
998 [[[-105.070162, 40.580083], [-105.070175, 40.5...
999 [[[-105.120617, 40.560044], [-105.120637, 40.5...
Name: geometry_coordinates, Length: 1000, dtype: object
[当前,我的代码在第一个列表/元素lon
中将index 0
附加到-105.077274
,但不是停留在index 0
中,而是循环到index 1
并接着附加-105.024284
。因此,当前lon看起来像
lon=[-105.077274,-105.024284...]
,但我试图让它先附加0 index
,就像lon=[-105.077274,-105.077005...]
一样,然后下移至index 1
。
import json import pandas as pd from pandas.io.json import json_normalize geojson = json.load(open("Data/Lanes.geojson")) geojson = json_normalize(geojson['features'], sep="_") print(geojson['geometry_coordinates']) lon = [] lat = [] for longitude in geojson['geometry_coordinates']: lon.append(longitude[0][0][0])
任何帮助,谢谢。
for l1 in geojson['geometry_coordinates']:
for l2 in l1:
for l3 in l2:
lon.append(l3[0])
lat.append(l3[1])