RuntimeWarning:较少的xa [xa <0] = -1(Geopandas)中遇到的无效值

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

问题

我正在尝试使用geopandas绘制每个地区的犯罪数据。我已经合并了shapefile数据和犯罪数据:

merged = merged[['geometry','Extortion']]
merged.head()

merged data

尝试

然后,我试图在地图上绘制犯罪数据:

variable = 'Extortion'
vmin, vmax = 120, 220
fig, ax = plt.subplots(1, figsize=(20, 10))
merged.plot(variable, cmap='Blues', linewidth=0.8, ax=ax, edgecolor='0.8')

错误

C:\Users\Navoda\Anaconda3\lib\site-packages\matplotlib\colors.py:504: 
RuntimeWarning: invalid value encountered in less
xa[xa < 0] = -1

没有参数'variable',它将加载到底图。问题出在变量上。我尝试按照大多数帖子的建议关闭警告。它仍然没有加载犯罪数据。

我检查了错误位置。但是,我不知道原因。

代码

if xa.dtype.kind == "f":
        xa *= self.N
        # Negative values are out of range, but astype(int) would truncate
        # them towards zero.
        xa[xa < 0] = -1
        # xa == 1 (== N after multiplication) is not out of range.
        xa[xa == self.N] = self.N - 1
        # Avoid converting large positive values to negative integers.
        np.clip(xa, -1, self.N, out=xa)
        xa = xa.astype(int)

注意:勒索栏没有NaN值。

我该如何解决这个问题?

python maps geopandas
1个回答
0
投票

我遇到了同样的错误,检查时是由于我的shapefile中的多边形未在数据中表示出来,因此它只需要替换在合并中创建的NAN,例如]]

merged['Extortion']=merged['Extortion'].fillna(0)
© www.soinside.com 2019 - 2024. All rights reserved.