始める無料で始める

洗練された Geopandas コロプレス図を作る

counts_dfpermits_by_district と結合したら、各評議会地区の許可数をその地区の面積で割って正規化した permit_density 列を作成します。次に、各評議会地区の建築プロジェクトについて、最終的な geopandas のコロプレス図を描画します。

この演習はコースの一部です

Pythonで可視化する地理空間データ

コースを見る

演習の手順

  • district をキーに permits_by_districtcounts_df をマージして、districts_and_permits を作成します。
  • apply() とラムダ式を使って、districts_and_permitspermit_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()
コードを編集して実行