GeoPandas,英国的地图,而不是南美的地图(如网站教程所示)

问题描述 投票:0回答:1

所以我有来自geopandas网站的此代码

# load data which contains long/lat of locations in England.
df = pd.read_csv(xxx.csv)

gdf = geopandas.GeoDataFrame(
    df, geometry=geopandas.points_from_xy(df.Longitude, df.Latitude))

print(gdf.head)

# plotting coordinates over a country level map
world = geopandas.read_file(geopandas.datasets.get_path("naturalearth_lowres"))

# then restrict this to the United Kingdom
ax = world[world.continent == 'South America'].plot(
    color='white', edgecolor='black')

# then plot the geodataframe on this
gdf.plot(ax=ax, color='red')
plt.show()

我想将其更改为英国或英国而不是南美,但是我似乎找不到如何用国家或类似名称代替大陆的方法。

任何帮助将不胜感激。

python data-analysis geopandas
1个回答
0
投票

尝试在此处替换您的代码行:

# then restrict this to the United Kingdom
ax = world[world.continent == 'South America'].plot(
    color='white', edgecolor='black')

带有此:

# then restrict this to the United Kingdom
ax = world[(world.name == "United Kingdom")].plot(
color='white', edgecolor='black')
© www.soinside.com 2019 - 2024. All rights reserved.