将 geopandas(世界地图)中的几何图形提取到我的数据框中
Extracting geometry in geopandas (worldmap) into my dataframe
我的数据框有一个国家名称但没有位置(坐标)所以我试图从 geopandas 世界地图中提取它。有谁知道如何从 world geopandans 获取几何列以匹配我的 drink.csv 数据框的国家名称,以便在我的 drinks.csv
中创建一个新列
来自 geopandas 的世界数据
我的数据集=drinks.csv
![[1]: https://i.stack.imgur.com/v0qp8.jpg
[2]:]2 https://i.stack.imgur.com/UGr3O.jpg
我建议您对列值使用索引和切片:
# set index of the country shapes to the name of the country
country_shapes_newindex = country_shapes.set_index('name')
# slice on the country shapes using the names of the countries from your drinks dataframe.
# the result is a DataFrame, select the geomtry column, and get their values.
# finally store this in a new column in your drinks DataFrame
drinks['geometry'] = country_shapes_newindex.loc[drinks['Country'].values]['geometry'].values
我的数据框有一个国家名称但没有位置(坐标)所以我试图从 geopandas 世界地图中提取它。有谁知道如何从 world geopandans 获取几何列以匹配我的 drink.csv 数据框的国家名称,以便在我的 drinks.csv
中创建一个新列来自 geopandas 的世界数据
我的数据集=drinks.csv
![[1]: https://i.stack.imgur.com/v0qp8.jpg [2]:]2 https://i.stack.imgur.com/UGr3O.jpg
我建议您对列值使用索引和切片:
# set index of the country shapes to the name of the country
country_shapes_newindex = country_shapes.set_index('name')
# slice on the country shapes using the names of the countries from your drinks dataframe.
# the result is a DataFrame, select the geomtry column, and get their values.
# finally store this in a new column in your drinks DataFrame
drinks['geometry'] = country_shapes_newindex.loc[drinks['Country'].values]['geometry'].values