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.

Python3: 接種状況ダッシュボードのデータを使ってワクチン接種済者をカウントする

Last updated at Posted at 2022-01-25

デジタル庁の 接種状況ダッシュボード のデータを処理して、ワクチン接種済者をカウントします。

データの取得

wget https://data.vrs.digital.go.jp/vaccination/opendata/latest/summary_by_date.csv

次を計算します。

ワクチン2回目接種済者
ワクチン2回目接種後、6ヶ月が経過した者
ワクチン3回目接種済者

count_vaccination.py
#! /usr/bin/python
# -*- coding: utf-8 -*-
#
#	csv_read.py
#
#						Jan/25/2022
#
import	sys
import	csv
import	datetime
#
from datetime import timedelta

# --------------------------------------------------------------------
def count_proc(array_aa,day_6months):
	second = 0
	second_6months = 0
	third = 0
	for unit in array_aa:
		dte = datetime.datetime.strptime(unit["date"], '%Y-%m-%d').date()
		if (dte < day_6months):
			second_6months += int(unit["count_second_shot_general"])
		second += int(unit["count_second_shot_general"])
		third += int(unit["count_third_shot_general"])
#
	sys.stderr.write("second = %d\n" % second)
	sys.stderr.write("second_6months = %d\n" % second_6months)
	sys.stderr.write("third = %d\n" % third)
# --------------------------------------------------------------------
def csv_read_proc(file_csv):
#
	fp = open(file_csv, 'r')
	reader = csv.DictReader(fp)
	array_aa = []
	for row in reader:
		array_aa.append(row)
#
	fp.close()
#
	return	array_aa
# --------------------------------------------------------------------
sys.stderr.write("*** 開始 ***\n")
file_csv = sys.argv[1]
sys.stderr.write(file_csv + "\n")
#
#today = datetime.datetime.today()
today = datetime.date.today()
sys.stderr.write("%s\n" % today)
#
delt = timedelta(days=184)
day_6months = today - delt
sys.stderr.write("%s\n" % day_6months)
#
try:
	array_aa = csv_read_proc(file_csv)
	sys.stderr.write("len(array_aa) = %d\n" % len(array_aa))
	count_proc(array_aa,day_6months)
except Exception as ee:
	sys.stderr.write("*** error ***\n")
	sys.stderr.write(str(ee) + "\n")
#
sys.stderr.write("*** 終了 ***\n")
# --------------------------------------------------------------------

実行結果

$ ./count_vaccination.py summary_by_date.csv
*** 開始 ***
summary_by_date.csv
2022-01-25
2021-07-25
len(array_aa) = 288
second = 93833803
second_6months = 28855283
third = 2629857
*** 終了 ***
ワクチン2回目接種済者 93,833,803
ワクチン2回目接種後、6ヶ月が経過した者 28,855,283
ワクチン3回目接種済者 2,629,857
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?