WHO の Coronavirus disease (COVID-2019) situation reports に基づいて集計したデータ COVID-19.csv を Python でグラフにする。
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv("https://oku.edu.mie-u.ac.jp/~okumura/python/data/COVID-19.csv",
index_col='Date', parse_dates=['Date'])
これで df.plot()
とすれば全部のコラムがプロットできるが,見にくいので,もうちょっとがんばってみる:
import matplotlib.dates as mdates
locator = mdates.AutoDateLocator()
formatter = mdates.ConciseDateFormatter(locator)
ax = plt.gca()
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.bar(df.index, df['Global Confirmed'])
ax.bar(df.index, df['Global Deaths'])
plt.legend(['Laboratory-Confirmed', 'Deaths'])
plt.savefig('COVID-19.svg', bbox_inches="tight")
対数グラフにするには ax.bar()
の2行を次のように変える:
ax.plot(df.index, df['Global Confirmed'], "o-")
ax.plot(df.index, df['Global Deaths'], "s-")
plt.yscale('log')
日本については,厚労省が発表しているが,とてもわかりくいので,とりあえず上記 WHO の日報から拾ったものを COVID-jp.csv として置いておく。なお,2022-02-05 の数は 33 となっていたがこれは明らかに 23 の誤記だと思われるので訂正しておいた。
横浜港に停泊したクルーズ船ダイヤモンド・プリンセス号については,厚労省の新着情報から「クルーズ船」で検索して集計した延べ人数は COVID-DP.csv のようになる。発表日ベースで集計した。検体採取の日は不明。どういう人を選んで検査したかによって陽性率は大きく変わるであろうから,要注意。NHKの2020-02-15 22:48のニュースによれば,「7日以前にウイルスに感染し、 7日に発症した乗客が最も多かった。その後の新たな発症者は、特に今月10日以降は急激に少なくなっていて、検疫の効果が出ていると考えている」(厚生労働省の担当者)とのことだが,これはよくわからない。
df = pd.read_csv("https://oku.edu.mie-u.ac.jp/~okumura/python/data/COVID-DP.csv",
index_col='Date', parse_dates=['Date'])
locator = mdates.AutoDateLocator()
formatter = mdates.ConciseDateFormatter(locator)
ax = plt.gca()
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
ax.bar(df.index, df['Examined'])
ax.bar(df.index, df['Positive'])
plt.legend(['Negative', 'Positive'])
陽性率とその95%信頼区間:
import numpy as np
from statsmodels.stats.proportion import proportion_confint
locator = mdates.AutoDateLocator()
formatter = mdates.ConciseDateFormatter(locator)
ax = plt.gca()
ax.xaxis.set_major_locator(locator)
ax.xaxis.set_major_formatter(formatter)
p = [x['Positive'] / x['Examined'] for i, x in df.iterrows()]
ci0, ci1 = np.array([proportion_confint(x['Positive'], x['Examined'], method='beta')
for i, x in df.iterrows()]).T
ax.errorbar(df.index, p, [p - ci0, ci1 - p], fmt="o", capsize=5)
[追記] 都道府県別新型コロナウイルス感染症患者数マップというすばらしいページを教えていただいた。こちらは厚労省のほか自治体からの情報も加えておられるとのことで,WHO の日報より多くなっている。
Last modified: