【发布时间】:2019-11-11 16:21:54
【问题描述】:
我有一个 json 文件,它给出了芝加哥社区的多边形。这是表单的一个小样本。
{'type': 'Feature',
'properties': {'PRI_NEIGH': 'Printers Row',
'SEC_NEIGH': 'PRINTERS ROW',
'SHAPE_AREA': 2162137.97139,
'SHAPE_LEN': 6864.247156},
'geometry': {'type': 'Polygon',
'coordinates': [[[-87.62760697485339, 41.87437097785366],
[-87.6275952566332, 41.873861712441126],
[-87.62756611032259, 41.873091933433905],
[-87.62755513014902, 41.872801941012725],
[-87.62754038267386, 41.87230261598636],
[-87.62752573582432, 41.8718067089444],
[-87.62751740010017, 41.87152447340544],
[-87.62749380061304, 41.87053328991345],
[-87.62748640976544, 41.87022285721281],
[-87.62747968351987, 41.86986997314866],
[-87.62746758964467, 41.86923545315858],
[-87.62746178584428, 41.868930955522266]
我想创建一个数据框,其中我有每个“SEC_NEIGH”,链接到这样的坐标
df['SEC_NEIGH'] = 'coordinates'
我尝试使用 for 循环遍历字典,但是当我这样做时,数据框只显示一个“_”
df = {}
for item in data:
if 'features' in item:
if 'properties' in item:
nn = item.get("properties").get("PRI_NEIGH")
if 'geometry' in item:
coords = item.get('geometry').get('coordinates')
df[nn] = coords
df_n=pd.DataFrame(df)
我期待每列都是一个单独的邻域,只有一个值,即坐标列表。相反,我的数据框输出为单个下划线('_')。我的 for 循环有问题吗?
【问题讨论】:
标签: python json for-loop data-science