小编skr*_*ber的帖子

将带有嵌套列表的 Geo json 转换为 Pandas 数据框

我有这种形式的大量地理 json:

 {'features': [{'properties': {'MARKET': 'Albany',
    'geometry': {'coordinates': [[[-74.264948, 42.419877, 0],
       [-74.262041, 42.425856, 0],
       [-74.261175, 42.427631, 0],
       [-74.260384, 42.429253, 0]]],
     'type': 'Polygon'}}},
  {'properties': {'MARKET': 'Albany',
    'geometry': {'coordinates': [[[-73.929627, 42.078788, 0],
       [-73.929114, 42.081658, 0]]],
     'type': 'Polygon'}}},
  {'properties': {'MARKET': 'Albuquerque',
    'geometry': {'coordinates': [[[-74.769198, 43.114089, 0],
       [-74.76786, 43.114496, 0],
       [-74.766474, 43.114656, 0]]],
     'type': 'Polygon'}}}],
 'type': 'FeatureCollection'}
Run Code Online (Sandbox Code Playgroud)

阅读json后:

import json
with open('x.json') as f:
    data = json.load(f)
Run Code Online (Sandbox Code Playgroud)

我将值读入列表,然后读入数据帧:

#to get a list of all markets
mkt=set([f['properties']['MARKET'] for f in data['features']])

#to create a list …
Run Code Online (Sandbox Code Playgroud)

python geojson python-3.x pandas

6
推荐指数
2
解决办法
8586
查看次数

标签 统计

geojson ×1

pandas ×1

python ×1

python-3.x ×1