我的数据框有一个国家/地区名称,但没有位置(坐标),所以我试图从geopandas worldmap中提取它。有没有人知道如何从世界地理人员那里获取几何列以匹配我的drink.csv数据帧的国家名称,以便在我的drink.csv中创建一个新列
![[1]: https://i.stack.imgur.com/v0qp8.jpg [2]:] 2 https://i.stack.imgur.com/UGr3O.jpg
答案 0 :(得分:2)
我建议您使用列值进行索引和切片:
# 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