【问题标题】:RuntimeWarning: Invalid value encountered in less xa[xa < 0] = -1 (Geopandas)RuntimeWarning:在 less xa[xa < 0] = -1 (Geopandas) 中遇到无效值
【发布时间】:2019-03-17 13:49:31
【问题描述】:

问题

我正在尝试使用 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 值。

我该如何解决这个问题?

【问题讨论】:

  • 你想用xa[xa &lt; 0] = -1做什么?这是无效的语法。
  • 您的 Extortion 列中有负值吗?
  • @NoSplitSherlock 这不是我的代码。尤其是错误指向的位置。它在 Anaconda3\lib\site-packages\matplotlib\colors.py:504
  • @martinfleis 不,没有任何负值。勒索列具有正浮点值
  • @Pubz 这似乎是 GeoPandas 或 matplotlib 中的错误。您使用的是什么版本?

标签: python maps geopandas


【解决方案1】:

我遇到了同样的错误,经过检查,这是由于我的 shapefile 中的多边形没有在数据中表示,所以它只需要替换在合并时创建的 NAN,例如

merged['Extortion']=merged['Extortion'].fillna(0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-13
    • 2013-01-29
    • 1970-01-01
    • 2019-04-10
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    • 2013-02-18
    相关资源
    最近更新 更多