洗練された Geopandas コロプレス図を作る
counts_df を permits_by_district と結合したら、各評議会地区の許可数をその地区の面積で割って正規化した permit_density 列を作成します。次に、各評議会地区の建築プロジェクトについて、最終的な geopandas のコロプレス図を描画します。
この演習はコースの一部です
Pythonで可視化する地理空間データ
演習の手順
districtをキーにpermits_by_districtとcounts_dfをマージして、districts_and_permitsを作成します。apply()とラムダ式を使って、districts_and_permitsにpermit_densityという新しい列を計算します。counts を area で割ってください。districts_and_permitsのコロプレス図を、permit_densityを用い、カラーマップはOrRd、アウトラインは黒で描画します。- 軸ラベル(longitude、latitude)と与えられたタイトルを追加し、プロットを表示します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Merge permits_by_district and counts_df
districts_and_permits = pd.merge(____, ____, on = ____)
# Create permit_density column
districts_and_permits['permit_density'] = districts_and_permits.apply(lambda row: row.____ / row.____, axis = 1)
print(districts_and_permits.head(2))
# Create choropleth plot
districts_and_permits.plot(column = ____, ____ = 'OrRd', ____ = 'black', legend = True)
# Add axis labels and title
plt.xlabel(____)
plt.ylabel(____)
plt.title('2017 Building Project Density by Council District')
plt.show()