- pandas - folium - matplotlib Nishiwaki's page

西脇の個人ページ

日本のコロナ累計陽性者数のコロプレスマップです。(更新日2022/07/26)


プロフィール

名前:西脇 彰
出身:高専(監獄?)
趣味:ゲーム,テニス



使用したオープンデータ

厚労省オープンデータ(csv)
47都道府県のポリゴンデータ(geojson)
OpenStreetMap
位置情報API
import folium import pandas as pd import json import re from pyodide.http import open_url from pyodide.http import pyfetch import asyncio url_positive = "https://raw.githubusercontent.com/L96-dead/covid_positive/main/covid19japan.csv" #陽性者数データ positive = pd.read_csv(open_url(url_positive)) positive.set_index('id') url_geodata = "https://raw.githubusercontent.com/L96-dead/covid_positive/main/prefectures.geojson" #ポリゴンデータ geodata_json = json.load(open_url(url_geodata)) response = await pyfetch(url="https://get.geojs.io/v1/ip/geo.json", method="GET") #位置情報取得API cal= str('C') output = f'{await response.json()}' geo_data = output def jj(output): #文字列を変換 str1 = output.replace("\'","\"") st = json.loads(str1) return st print('現在地>>',jj(output)['latitude'],jj(output)['longitude']) def folium_del_legend(choropleth: folium.Choropleth): #凡例を削除 del_list = [] for child in choropleth._children: if child.startswith('color_map'): del_list.append(child) for del_item in del_list: choropleth._children.pop(del_item) return choropleth m = folium.Map(location=[38.00, 138.00], zoom_start=5, tiles="cartodbpositron") #map生成 folium.Marker(location=[jj(output)['latitude'],jj(output)['longitude']],popup="現在地").add_to(m) #現在地にマーカー folium.Choropleth( geo_data = geodata_json, name = 'choropleth', data = positive, columns = ['id','npatients'], key_on = 'feature.properties.pref', fill_opacity = 0.7, line_opacity = 0.2, line_color ='red', fill_color ='YlOrBr', nan_fill_color="white", threshold_scale=[0, 30000, 50000, 100000, 300000, 500000, 1000000, 2000000], legend_name='COVID-19 cases' ).add_to(m) m