2017-06-04 3 views
0

私のデータフレームには国名がありますが、位置(座標)はありませんので、geopandas worldmapからデータフレームを抽出しようとしています。誰もが私のdrinks.csvにgeopandasからgeopandas(ワールドマップ)のジオメトリをデータフレームに抽出する

世界のデータを新しい列を作成するために私のdrink.csvのデータフレームの国名に合わせて世界のgeopandansからジオメトリ列を取得する方法を知ってい enter image description here

私のデータセット= drinks.csv my data set

![[1]: https://i.stack.imgur.com/v0qp8.jpg [2]:]2https://i.stack.imgur.com/UGr3O.jpg

答えて

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 
関連する問題