我有一个关于通过 Python 中的 GeoDataFrame 绘制我的国家的问题。
完成基本过程后,我得到了一个在我的国家/地区显示的数据框。
代码段引发有关数据帧大小的错误。
我该如何解决它?
这是我的数据帧
index Longitude Latitude geometry
0 0 27.000 41.000 POINT (27.00000 41.00000)
1 1 27.400 37.800 POINT (27.40000 37.80000)
2 2 27.300 37.850 POINT (27.30000 37.85000)
3 3 28.900 40.500 POINT (28.90000 40.50000)
4 4 36.100 36.100 POINT (36.10000 36.10000)
... ... ... ... ...
317 317 27.414 36.929 POINT (27.41400 36.92900)
318 318 38.514 37.596 POINT (38.51400 37.59600)
319 319 29.697 37.948 POINT (29.69700 37.94800)
320 320 28.173 40.890 POINT (28.17300 40.89000)
321 321 39.081 38.390 POINT (39.08100 38.39000)
这是我的代码片段
df_point_TURKEY = df_point[df_point["Country"] == "TURKEY"]
df_point_TURKEY = df_point_TURKEY.drop("Country", axis=1)
df_point_TURKEY.reset_index(drop=True, inplace=True)
df_point_TURKEY["index"] = np.arange(0,len(df_point_TURKEY))
geometry = [Point(xy) for xy in zip(df_point_TURKEY['Longitude'], df_point_TURKEY['Latitude'])]
gdf = GeoDataFrame(df_point, geometry=geometry)
#this is a simple map that goes with geopandas
world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
gdf.plot(ax=world[world["name"] == "Turkey"].plot(figsize=(16, 8)),
marker='o',
color='red',
markersize=15
);
plt.title('Earthquakes occurred from 2100 BC in Turkey',fontsize = 25)
plt.savefig('images/image12.png')
plt.show()
错误:ValueError: Length of values does not match length of index
我忘了更改代码
取代
gdf = GeoDataFrame(df_point, geometry=geometry)
跟
gdf = GeoDataFrame(df_point_TURKEY, geometry=geometry)