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

问题描述 投票:0回答:1

目标是读取shapefile,获取每个多边形的面积(市镇,并在名为'Area'的新列中添加该面积。

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

当我运行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线程,但是没有解决方案。

python-3.x pandas indexing shapefile geopandas
1个回答
0
投票

您应该可以直接执行以下操作,

© www.soinside.com 2019 - 2024. All rights reserved.