0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Pythonでコロナ感染者数を軽く集計した話

Posted at

コード

使っているモジュール
pandas (pip install pandasでインストール可能)
matplotlib (pip install matplotlibでインストール可能)

main.py
import pandas
from matplotlib import pyplot

hyouji = ["ALL","Hokkaido","Aomori","Iwate","Miyagi","Akita","Yamagata","Fukushima","Ibaraki","Tochigi","Gunma","Saitama","Chiba","Tokyo","Kanagawa","Niigata","Toyama","Ishikawa","Fukui","Yamanashi","Nagano","Gifu","Shizuoka","Aichi","Mie","Shiga","Kyoto","Osaka","Hyogo","Nara","Wakayama","Tottori","Shimane","Okayama","Hiroshima","Yamaguchi","Tokushima","Kagawa","Ehime","Kochi","Fukuoka","Saga","Nagasaki","Kumamoto","Oita","Miyazaki","Kagoshima","Okinawa"]

for i in hyouji:
    pyplot.figure()
    pyplot.title(f"{i}")
    
    score = pandas.read_csv("https://covid19.mhlw.go.jp/public/opendata/newly_confirmed_cases_daily.csv",encoding="utf-8")
    score2 = score[i]
    date = [score["Date"][a][0:6] for a in range(0,len(score["Date"]))]

    pyplot.xticks(rotation=30)

    pyplot.bar(date, score2)

    pyplot.savefig(f"コロナ感染者数/コロナ - {i}.png")

大まかに、やっていること
1 感染者数のCSVデータを収集
2 X軸をyyyy/MM形式にする※1
3 Y軸は感染者数値にする
4 棒グラフ(?)としてグラフを生成する
5 png画像で出力※2
という流れ
※1 よって、一ヶ月単位での感染者数表示とする
※2 例えば、北海道なら、コロナ - Hokkaido.pngという名前で保存される

グラフの例

コロナ - ALL.png(全国の感染者数)で試した場合
コロナ - ALL.png
matplotlibを使っているため、結構きれいに出てきます。

まとめ

結構使えると思います
以上!((

ご視聴ありがとうございました!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?