索引超出地理图范围

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

我正在尝试创建一个 KDE 图来显示每个犯罪类别的地理密度。数据集是费城犯罪事件费城警察区边界

gdf = data.copy()
gdf['Coordinates'] = list(zip(gdf.point_x, gdf.point_y))
gdf.Coordinates = gdf.Coordinates.apply(Point)
gdf = gpd.GeoDataFrame(
    gdf,
    geometry='Coordinates',
    crs="epsg:4326"
)

# GDF of crime incidents
crime_data = gdf.loc[gdf["text_general_code"] == 'Thefts']

# Boundaries of the region
land = pd_boundary.unary_union
land = gpd.GeoDataFrame(gpd.GeoSeries(land), columns=["geometry"])
land = land.set_geometry("geometry")
land.crs = "epsg:4326"

当我尝试绘制 KDE 图时,我异常地得到

IndexError: index out of range
。 我尝试过检查空值,并在线搜索可能的原因,但没有帮助。

ax = gplt.polyplot(land)
gplt.kdeplot(
    crime_data,
    ax=ax
)

任何有关如何调试的想法都会非常有帮助。

pandas matplotlib geopandas kernel-density geoplot
1个回答
0
投票

我在示例数据上测试了您的代码,并能够重现您的问题。如果我从

na
中删除所有
data
值,我就能得出这个数字。所以你可以在制作
gpd.GeoDataFrame
:

之前插入这些代码行
data_na = data.dropna(axis=0)
gdf = data_na.copy()
© www.soinside.com 2019 - 2024. All rights reserved.