我正在尝试使用 geopandas 绘制每个地区的犯罪数据。我已合并shapefile
数据和犯罪数据:
merged = merged[['geometry','Extortion']]
merged.head()
然后,我试图在地图上绘制犯罪数据:
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
没有参数“变量”,它将加载到基本映射。问题出在变量上。我尝试按照大多数帖子的建议关闭警告。它仍然没有加载犯罪数据。
我检查了错误位置。但是,我不知道原因。
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
值。
如何解决此问题?
答案 0 :(得分:0)
我遇到了同样的错误,经检查,这是由于我的shapefile中的多边形未在数据中表示出来,因此它只需要替换在合并中创建的NAN,例如
merged['Extortion']=merged['Extortion'].fillna(0)