np.nan
至少在我的版本中,GeoPandas看起来不喜欢0.8.1
。当我将a传递给np.nan
GeoSeries时,它就变成了a None
,我不知道该怎么做np.nan
。
import geopandas as gpd
from shapely.geometry import Point as pt
import numpy as np
lt = [np.nan, np.nan, pt([1,2]), pt([0,0])]
ser = gpd.GeoSeries(lt)
# Somehow the first two elements of ser became None
ser[0] is None #True
np.isnan(ser[0]) #TypeError
# I don't even know how to put a np.nan in the GeoSeries
ser[0] = np.nan # This doesn't work
# These tests still give the same results
ser[0] is None #True
np.isnan(ser[0]) #TypeError
我想念什么吗?这是预期的行为吗?有没有办法得到np.nan
一个GeoSeries
?
在文档中,有两个部分可以回答您的问题。
在有关GeoSeries的部分中
A
GeoSeries
本质上是一个向量,其中向量中的每个条目都是一组与一个观测值相对应的形状。geopandas具有三个基本类别的几何对象(实际上是形状对象):
- 点/多点
- 线/多线
- 多边形/多面体
请注意,尽管在某些情况下某些导出操作将失败,但是GeoSeries中的所有条目不必具有相同的几何类型。
在有关缺失和空几何的部分中
缺少几何形状是中的未知值
GeoSeries
。标量对象(访问GeoSeries的单个元素时)是PythonNone
对象。
因此,geopandas需要该行为。
评论
在最新版本中,可能会产生NaN
不建议使用的-value。
如果您进行跑步gpd.GeoSeries([np.nan, np.nan, pt([1,2]), pt([0,0])])
,则所得系列为类型GeoSeries
。
如果混合使用浮点数和点这样gpd.GeoSeries([10, np.nan, pt([1,2]), pt([0,0])])
的结果,则结果的类型Series
为立即回退,其中包含一个NaN
值。
在geopandas 0.8.0
此提出警告:You are passing non-geometry data to the GeoSeries constructor.
在将来的版本中,这将引发错误。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句