小编Bal*_*Man的帖子

向 GeoDataFrame 添加新列,当它匹配时,它说值的长度与索引不匹配

目标是读取 shapefile,获取每个多边形(城市)的面积,并将该面积添加到名为“面积”的新列中。

cs = gpd.read_file('munis.shp')
area_fd = []
area = cs['geometry'].map(lambda p: p.area / 10**6)
area_fd.append(area)
cs = cs.assign(Area =  area_fd) #or cs['Area'] = area_fd
Run Code Online (Sandbox Code Playgroud)

当我运行时,print(cs['NAME_2'].head)它返回 38 munis (0-38) 并print(area_fd)给出 38 个值。但是当我运行代码时,它说ValueError: Length of values does not match length of index。我已经查找了类似的 GISSE 和 SO 线程,但没有解决方案有效。

indexing shapefile python-3.x pandas geopandas

0
推荐指数
1
解决办法
3865
查看次数

标签 统计

geopandas ×1

indexing ×1

pandas ×1

python-3.x ×1

shapefile ×1