🐕
COVID-19オープンデータに緯度と経度を追加してdeckglで可視化
元のCSVはこんな感じです
緯度、経度を追加するPythonプログラム
import pandas as pd
import numpy as np
covid_df = pd.read_csv('./covid19japan.csv')
pref_list =np.array([
["北海道","青森県","岩手県","宮城県","秋田県",
"山形県","福島県","茨城県","栃木県","群馬県",
"埼玉県","千葉県","東京都","神奈川県","新潟県",
"富山県","石川県","福井県","山梨県","長野県",
"岐阜県","静岡県","愛知県","三重県","滋賀県",
"京都府","大阪府","兵庫県","奈良県","和歌山県",
"鳥取県","島根県","岡山県","広島県","山口県",
"徳島県","香川県","愛媛県","高知県","福岡県",
"佐賀県","長崎県","熊本県","大分県","宮崎県","鹿児島県","沖縄県"],
[141.347899,140.740593,141.152667,140.872103,140.102334,
140.363634,140.467521,140.446793,139.883565,139.060156,
139.648933,140.123308,139.691704,139.642514,139.023221,
137.211338,136.625573,136.221642,138.568449,138.181224,
136.722291,138.383054,136.906565,136.508591,135.86859,
135.755608,135.519711,135.183025,135.832744,135.167506,
134.237672,133.050499,133.934675,132.459622,131.4705,
134.559303,134.043444,132.765362,133.53108,130.418314,
130.298822,129.873756,130.741667,131.612591,131.423855,130.557981,127.680932],
[43.063968,40.824623,39.703531,38.268839,39.7186,
38.240437,37.750299,36.341813,36.565725,36.391208,
35.857428,35.605058,35.689521,35.447753,37.902418,
36.69529,36.594682,36.065219,35.664158,36.651289,
35.391227,34.976978,35.180188,34.730283,35.004531,
35.021004,34.686316,34.691279,34.685333,34.226034,
35.503869,35.472297,34.661772,34.39656,34.186121,
34.06577,34.340149,33.84166,33.559705,33.606785,
33.249367,32.744839,32.789828,33.238194,31.91109,31.560148,26.212401]]).transpose()
pref_df = pd.DataFrame(pref_list,columns=['name_jp', 'lng', 'lat'])
result = pd.merge(covid_df, pref_df, on='name_jp')
result.to_csv('covid_19_with_lnglat.csv')
Appendix ~こんな可視化をしてみた~
deckglを使って地図にプロットできます。今回はScatterで散布図的に、感染者数が多いところに円がおおきくなるようにしました
※deckglは、別途MAP APIの利用登録が必要です。
import pydeck as pdk
import pandas as pd
JAPAN_COVID_19 = pd.read_csv('./covid_19_with_lnglat.csv')
layer = pdk.Layer(
'ScatterplotLayer',
JAPAN_COVID_19,
get_position=['lng', 'lat'],
auto_highlight=True,
get_radius='ndeaths * 100 ',
get_fill_color='[180, 0, 200, 140]',
pickable=True)
# Set the viewport location
view_state = pdk.ViewState(
longitude=139,
latitude=35,
zoom=6,
min_zoom=5,
max_zoom=15,
pitch=40.5,
bearing=-27.36)
# Combined all of it and render a viewport
r = pdk.Deck(layers=[layer], initial_view_state=view_state)
r.to_html('covid_19.html')
こんな風にできます
Discussion
もしかして緯度と経度とかも返してくれるAPIあったり、、、?