{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "20a03f4a",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import datetime\n",
"from datetime import date, timedelta"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "bd72ce5b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" date | \n",
" date_positive | \n",
" date_dose1 | \n",
" date_dose2 | \n",
" vaxtype | \n",
" state | \n",
" age | \n",
" male | \n",
" bid | \n",
" malaysian | \n",
" comorb | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 2020-03-17 | \n",
" 2020-03-12 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" Johor | \n",
" 34 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" 2020-03-17 | \n",
" 2020-03-14 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" Sarawak | \n",
" 60 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 2 | \n",
" 2020-03-20 | \n",
" 2020-03-11 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" Sabah | \n",
" 58 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" 2020-03-21 | \n",
" 2020-03-17 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" Kelantan | \n",
" 69 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 4 | \n",
" 2020-03-21 | \n",
" 2020-03-13 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" Melaka | \n",
" 50 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 5 | \n",
" 2020-03-21 | \n",
" 2020-03-21 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" Sarawak | \n",
" 39 | \n",
" 0 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 6 | \n",
" 2020-03-21 | \n",
" 2020-03-14 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" W.P. Kuala Lumpur | \n",
" 57 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 7 | \n",
" 2020-03-22 | \n",
" 2020-03-18 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" Perlis | \n",
" 48 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 8 | \n",
" 2020-03-22 | \n",
" 2020-03-14 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" Pulau Pinang | \n",
" 73 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 9 | \n",
" 2020-03-22 | \n",
" 2020-03-20 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" Sarawak | \n",
" 80 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" date date_positive date_dose1 date_dose2 vaxtype state \\\n",
"0 2020-03-17 2020-03-12 NaN NaN NaN Johor \n",
"1 2020-03-17 2020-03-14 NaN NaN NaN Sarawak \n",
"2 2020-03-20 2020-03-11 NaN NaN NaN Sabah \n",
"3 2020-03-21 2020-03-17 NaN NaN NaN Kelantan \n",
"4 2020-03-21 2020-03-13 NaN NaN NaN Melaka \n",
"5 2020-03-21 2020-03-21 NaN NaN NaN Sarawak \n",
"6 2020-03-21 2020-03-14 NaN NaN NaN W.P. Kuala Lumpur \n",
"7 2020-03-22 2020-03-18 NaN NaN NaN Perlis \n",
"8 2020-03-22 2020-03-14 NaN NaN NaN Pulau Pinang \n",
"9 2020-03-22 2020-03-20 NaN NaN NaN Sarawak \n",
"\n",
" age male bid malaysian comorb \n",
"0 34 1 0 1 1 \n",
"1 60 1 0 1 1 \n",
"2 58 1 0 1 1 \n",
"3 69 1 0 1 1 \n",
"4 50 1 0 1 1 \n",
"5 39 0 0 1 1 \n",
"6 57 1 0 1 1 \n",
"7 48 1 0 1 1 \n",
"8 73 1 0 1 1 \n",
"9 80 0 1 1 1 "
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"url_linelist = 'https://raw.githubusercontent.com/MoH-Malaysia/covid19-public/main/epidemic/linelist/linelist_deaths.csv'\n",
"df = pd.read_csv(url_linelist, dtype=str)\n",
"df.head(10)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6b38da72",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" date | \n",
" date_positive | \n",
" date_dose1 | \n",
" date_dose2 | \n",
" vaxtype | \n",
" state | \n",
" age | \n",
" male | \n",
" bid | \n",
" malaysian | \n",
" comorb | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 2020-03-17 | \n",
" 2020-03-12 | \n",
" NaN | \n",
" 2021-09-19 | \n",
" NaN | \n",
" Johor | \n",
" 34 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" 2020-03-17 | \n",
" 2020-03-14 | \n",
" NaN | \n",
" 2021-09-19 | \n",
" NaN | \n",
" Sarawak | \n",
" 60 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 2 | \n",
" 2020-03-20 | \n",
" 2020-03-11 | \n",
" NaN | \n",
" 2021-09-19 | \n",
" NaN | \n",
" Sabah | \n",
" 58 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 3 | \n",
" 2020-03-21 | \n",
" 2020-03-17 | \n",
" NaN | \n",
" 2021-09-19 | \n",
" NaN | \n",
" Kelantan | \n",
" 69 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 4 | \n",
" 2020-03-21 | \n",
" 2020-03-13 | \n",
" NaN | \n",
" 2021-09-19 | \n",
" NaN | \n",
" Melaka | \n",
" 50 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 5 | \n",
" 2020-03-21 | \n",
" 2020-03-21 | \n",
" NaN | \n",
" 2021-09-19 | \n",
" NaN | \n",
" Sarawak | \n",
" 39 | \n",
" 0 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 6 | \n",
" 2020-03-21 | \n",
" 2020-03-14 | \n",
" NaN | \n",
" 2021-09-19 | \n",
" NaN | \n",
" W.P. Kuala Lumpur | \n",
" 57 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 7 | \n",
" 2020-03-22 | \n",
" 2020-03-18 | \n",
" NaN | \n",
" 2021-09-19 | \n",
" NaN | \n",
" Perlis | \n",
" 48 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 8 | \n",
" 2020-03-22 | \n",
" 2020-03-14 | \n",
" NaN | \n",
" 2021-09-19 | \n",
" NaN | \n",
" Pulau Pinang | \n",
" 73 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 9 | \n",
" 2020-03-22 | \n",
" 2020-03-20 | \n",
" NaN | \n",
" 2021-09-19 | \n",
" NaN | \n",
" Sarawak | \n",
" 80 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" date date_positive date_dose1 date_dose2 vaxtype state \\\n",
"0 2020-03-17 2020-03-12 NaN 2021-09-19 NaN Johor \n",
"1 2020-03-17 2020-03-14 NaN 2021-09-19 NaN Sarawak \n",
"2 2020-03-20 2020-03-11 NaN 2021-09-19 NaN Sabah \n",
"3 2020-03-21 2020-03-17 NaN 2021-09-19 NaN Kelantan \n",
"4 2020-03-21 2020-03-13 NaN 2021-09-19 NaN Melaka \n",
"5 2020-03-21 2020-03-21 NaN 2021-09-19 NaN Sarawak \n",
"6 2020-03-21 2020-03-14 NaN 2021-09-19 NaN W.P. Kuala Lumpur \n",
"7 2020-03-22 2020-03-18 NaN 2021-09-19 NaN Perlis \n",
"8 2020-03-22 2020-03-14 NaN 2021-09-19 NaN Pulau Pinang \n",
"9 2020-03-22 2020-03-20 NaN 2021-09-19 NaN Sarawak \n",
"\n",
" age male bid malaysian comorb \n",
"0 34 1 0 1 1 \n",
"1 60 1 0 1 1 \n",
"2 58 1 0 1 1 \n",
"3 69 1 0 1 1 \n",
"4 50 1 0 1 1 \n",
"5 39 0 0 1 1 \n",
"6 57 1 0 1 1 \n",
"7 48 1 0 1 1 \n",
"8 73 1 0 1 1 \n",
"9 80 0 1 1 1 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# wrangle relevant date columns\n",
"df.date = pd.to_datetime(df.date, errors='coerce').dt.date\n",
"df.date_positive = pd.to_datetime(df.date_positive, errors='coerce').dt.date\n",
"assert len(df[df.date.isnull()]) == len(df[df.date_positive.isnull()]) == 0\n",
"df.date_dose2 = pd.to_datetime(df.date_dose2, errors='coerce').dt.date\n",
"\n",
"# fill blank dates for computation of full vax \n",
"df.date_dose2 = df.date_dose2.fillna(date.today()+timedelta(1)) \n",
"df.head(10)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "c1a56478",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" date | \n",
" date_positive | \n",
" date_dose1 | \n",
" date_dose2 | \n",
" vaxtype | \n",
" state | \n",
" age | \n",
" male | \n",
" bid | \n",
" malaysian | \n",
" comorb | \n",
"
\n",
" \n",
" \n",
" \n",
" 22734 | \n",
" 2021-09-17 | \n",
" 2021-09-01 | \n",
" 2021-06-15 | \n",
" 2021-07-06 | \n",
" Pfizer | \n",
" Johor | \n",
" 68 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 22735 | \n",
" 2021-09-17 | \n",
" 2021-09-05 | \n",
" 2021-06-16 | \n",
" 2021-07-07 | \n",
" Pfizer | \n",
" Johor | \n",
" 67 | \n",
" 1 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 22741 | \n",
" 2021-09-17 | \n",
" 2021-09-10 | \n",
" 2021-06-20 | \n",
" 2021-07-11 | \n",
" Sinovac | \n",
" Terengganu | \n",
" 77 | \n",
" 0 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 22742 | \n",
" 2021-09-17 | \n",
" 2021-09-12 | \n",
" 2021-06-03 | \n",
" 2021-06-24 | \n",
" Sinovac | \n",
" Terengganu | \n",
" 47 | \n",
" 0 | \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" date date_positive date_dose1 date_dose2 vaxtype state \\\n",
"22734 2021-09-17 2021-09-01 2021-06-15 2021-07-06 Pfizer Johor \n",
"22735 2021-09-17 2021-09-05 2021-06-16 2021-07-07 Pfizer Johor \n",
"22741 2021-09-17 2021-09-10 2021-06-20 2021-07-11 Sinovac Terengganu \n",
"22742 2021-09-17 2021-09-12 2021-06-03 2021-06-24 Sinovac Terengganu \n",
"\n",
" age male bid malaysian comorb \n",
"22734 68 1 0 1 1 \n",
"22735 67 1 0 1 1 \n",
"22741 77 0 0 1 1 \n",
"22742 47 0 0 1 1 "
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# keep only those who were infected at least 14 days after dose 2\n",
"fvax = df[(df.date_positive - df.date_dose2).dt.days > 13].copy() \n",
"fvax = fvax[fvax.date == date(2021,9,17)]\n",
"fvax.head(10)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}