[英]Geting error: 'Int64Index' object has no attribute 'get_values'. What am I doing wrong?
我对数据科学有点陌生,我正在为这个项目而苦苦挣扎,我希望能得到一些帮助。 所以,我正在使用 some.shp 文件来获取一些具有其他功能的类似 choropleth 的地图,因为我遇到了这个错误,我的运气不好。
shp_path = '.../Comuna.shp'
sf = shp.Reader(shp_path)
def read_shapefile(sf):
fields = [x[0] for x in sf.fields][1:]
records = sf.records()
shps = [s.points for s in sf.shapes()]
df = pd.DataFrame(columns=fields, data=records)
df = df.assign(coords=shps)
return df
df = read_shapefile(sf)
REGION PROVINCIA COMUNA NOM_REGION NOM_PROVIN \
0 13 131 13114 REGIÓN METROPOLITANA DE SANTIAGO SANTIAGO
1 13 131 13115 REGIÓN METROPOLITANA DE SANTIAGO SANTIAGO
NOM_COMUNA coords
0 LAS CONDES [(-70.47950849099993, -33.36433197899993), (-7...
1 LO BARNECHEA [(-70.32034044899996, -33.105245486999934), (-...
df[df.NOM_COMUNA == 'SANTIAGO']
REGION PROVINCIA COMUNA NOM_REGION NOM_PROVIN \
25 13 131 13101 REGIÓN METROPOLITANA DE SANTIAGO SANTIAGO
NOM_COMUNA coords
25 SANTIAGO [(-70.66527655199997, -33.42827810699998), (-7...
def plot_shape(id, s=None):
""" PLOTS A SINGLE SHAPE """
plt.figure()
ax = plt.axes()
ax.set_aspect('equal')
shape_ex = sf.shape(id)
x_lon = np.zeros((len(shape_ex.points),1))
y_lat = np.zeros((len(shape_ex.points),1))
for ip in range(len(shape_ex.points)):
x_lon[ip] = shape_ex.points[ip][0]
y_lat[ip] = shape_ex.points[ip][1]
plt.plot(x_lon,y_lat)
x0 = np.mean(x_lon)
y0 = np.mean(y_lat)
plt.text(x0, y0, s, fontsize=10)
# use bbox (bounding box) to set plot limits
plt.xlim(shape_ex.bbox[0],shape_ex.bbox[2])
return x0, y0
comuna = 'SANTIAGO'
com_id =df[df.NOM_COMUNA == comuna].index.get_values()[0]
plot_shape(com_id, comuna)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-46-732395dd9018> in <module>
1 comuna = 'SANTIAGO'
----> 2 com_id =df[df.NOM_COMUNA == comuna].index.get_values()[0]
3 plot_shape(com_id, comuna)
AttributeError: 'Int64Index' object has no attribute 'get_values'
我已经构建了一些其他函数来获取这些地图,但我认为问题的根源在于这个。 非常感谢。
尝试df[df.NOM_COMUNA == comuna].index.values
代替。
您可以在其源代码中阅读更多关于 Int64Index 可以/不能在此处执行的操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.