Last active
December 23, 2021 03:37
-
-
Save pshapiro/b3f4016294890111ebac17fded111b1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "615c1789-786a-43e0-a83a-142b85d806c5", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import pandas as pd" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"id": "8ec8d712-9477-408d-85f8-5793d7d654fe", | |
"metadata": {}, | |
"source": [ | |
"__Data__: VAERS 2021 ([download data set](https://vaers.hhs.gov/eSubDownload/index.jsp?fn=2021VAERSData.zip))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "ba9398fb-0a05-4246-be43-3d467adf2c1f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/Users/paulshapiro/opt/anaconda3/lib/python3.8/site-packages/IPython/core/interactiveshell.py:3165: DtypeWarning: Columns (7,9,10,12,15,23,31) have mixed types.Specify dtype option on import or set low_memory=False.\n", | |
" has_raised = await self.run_ast_nodes(code_ast.body, cell_name,\n" | |
] | |
} | |
], | |
"source": [ | |
"df_2021VAERSVAX_csv = pd.read_csv(r'/Users/paulshapiro/Downloads/2021VAERSData/2021VAERSVAX.csv')\n", | |
"df_2021VAERSSYMPTOMS_csv = pd.read_csv(r'/Users/paulshapiro/Downloads/2021VAERSData/2021VAERSSYMPTOMS.csv')\n", | |
"df_2021VAERSDATA_csv = pd.read_csv(r'/Users/paulshapiro/Downloads/2021VAERSData/2021VAERSDATA.csv')\n", | |
"temp_df = df_2021VAERSSYMPTOMS_csv.drop_duplicates(subset='VAERS_ID')\n", | |
"df4 = df_2021VAERSVAX_csv.merge(temp_df, left_on=['VAERS_ID'], right_on=['VAERS_ID'], how='left', suffixes=['_df_2021VAERSVAX_csv', '_df_2021VAERSSYMPTOMS_csv'])\n", | |
"temp_df = df_2021VAERSDATA_csv.drop_duplicates(subset='VAERS_ID')\n", | |
"df5 = df4.merge(temp_df, left_on=['VAERS_ID'], right_on=['VAERS_ID'], how='left', suffixes=['_df4', '_df_2021VAERSDATA_csv'])\n", | |
"df5 = df5[df5['VAX_NAME'].astype('str').str.contains('COVID', na=False)]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "87c85b83-3575-4973-8d96-b1c4bfcddfd2", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"sym1 = df5.copy(deep=True)\n", | |
"sym2 = df5.copy(deep=True)\n", | |
"sym3 = df5.copy(deep=True)\n", | |
"sym4 = df5.copy(deep=True)\n", | |
"sym5 = df5.copy(deep=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"id": "d3dfc346-24c8-4cf8-b5f9-3a18c9b3ced4", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"sym1 = sym1[(~sym1['SYMPTOM1'].astype('str').str.contains('Foetal', na=False)) & ((sym1['SYMPTOM1'].astype('str').apply(lambda val: any(s in val for s in ['Death', 'death']))))]\n", | |
"sym2 = sym2[(~sym2['SYMPTOM2'].astype('str').str.contains('Foetal', na=False)) & ((sym2['SYMPTOM2'].astype('str').apply(lambda val: any(s in val for s in ['Death', 'death']))))]\n", | |
"sym3 = sym3[(~sym3['SYMPTOM3'].astype('str').str.contains('Foetal', na=False)) & ((sym3['SYMPTOM3'].astype('str').apply(lambda val: any(s in val for s in ['Death', 'death']))))]\n", | |
"sym4 = sym4[(~sym4['SYMPTOM4'].astype('str').str.contains('Foetal', na=False)) & ((sym4['SYMPTOM4'].astype('str').apply(lambda val: any(s in val for s in ['Death', 'death']))))]\n", | |
"sym5 = sym5[(~sym5['SYMPTOM5'].astype('str').str.contains('Foetal', na=False)) & ((sym5['SYMPTOM5'].astype('str').apply(lambda val: any(s in val for s in ['Death', 'death']))))]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"id": "07c3a258-9559-4e7b-a174-76029e5d4f84", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"death = pd.concat([sym1, sym2, sym3, sym4, sym5], axis=0)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"id": "be8843fa-2b5c-4f24-b975-fed9e6765098", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"8201" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"sym1.shape[0] + sym2.shape[0] + sym3.shape[0] + sym4.shape[0] + sym5.shape[0]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 28, | |
"id": "ba1c3dff-6e60-493e-bdaf-460949f5cf9a", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div><div id=a2032735-1cf3-4502-b4e4-a84897fe79d4 style=\"display:none; background-color:#9D6CFF; color:white; width:200px; height:30px; padding-left:5px; border-radius:4px; flex-direction:row; justify-content:space-around; align-items:center;\" onmouseover=\"this.style.backgroundColor='#BA9BF8'\" onmouseout=\"this.style.backgroundColor='#9D6CFF'\" onclick=\"window.commands?.execute('create-mitosheet-from-dataframe-output');\">See Full Dataframe in Mito</div> <script> if (window.commands.hasCommand('create-mitosheet-from-dataframe-output')) document.getElementById('a2032735-1cf3-4502-b4e4-a84897fe79d4').style.display = 'flex' </script> <table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>VAERS_ID</th>\n", | |
" <th>VAX_TYPE</th>\n", | |
" <th>VAX_MANU</th>\n", | |
" <th>VAX_LOT</th>\n", | |
" <th>VAX_DOSE_SERIES</th>\n", | |
" <th>VAX_ROUTE</th>\n", | |
" <th>VAX_SITE</th>\n", | |
" <th>VAX_NAME</th>\n", | |
" <th>SYMPTOM1</th>\n", | |
" <th>SYMPTOMVERSION1</th>\n", | |
" <th>...</th>\n", | |
" <th>PRIOR_VAX</th>\n", | |
" <th>SPLTTYPE</th>\n", | |
" <th>FORM_VERS</th>\n", | |
" <th>TODAYS_DATE</th>\n", | |
" <th>BIRTH_DEFECT</th>\n", | |
" <th>OFC_VISIT</th>\n", | |
" <th>ER_ED_VISIT</th>\n", | |
" <th>ALLERGIES</th>\n", | |
" <th>POLITICS</th>\n", | |
" <th>AGE_DECADE</th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>1463</th>\n", | |
" <td>918065</td>\n", | |
" <td>COVID19</td>\n", | |
" <td>MODERNA</td>\n", | |
" <td>025J20-2A</td>\n", | |
" <td>1</td>\n", | |
" <td>IM</td>\n", | |
" <td>NaN</td>\n", | |
" <td>COVID19 (COVID19 (MODERNA))</td>\n", | |
" <td>Death</td>\n", | |
" <td>23.1</td>\n", | |
" <td>...</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>2</td>\n", | |
" <td>01/04/2021</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>- Clozaril - Tegretol</td>\n", | |
" <td>blue</td>\n", | |
" <td>60s</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>1759</th>\n", | |
" <td>918388</td>\n", | |
" <td>COVID19</td>\n", | |
" <td>PFIZER\\BIONTECH</td>\n", | |
" <td>EL0140</td>\n", | |
" <td>1</td>\n", | |
" <td>IM</td>\n", | |
" <td>LA</td>\n", | |
" <td>COVID19 (COVID19 (PFIZER-BIONTECH))</td>\n", | |
" <td>Death</td>\n", | |
" <td>23.1</td>\n", | |
" <td>...</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>2</td>\n", | |
" <td>01/04/2021</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NKA</td>\n", | |
" <td>red</td>\n", | |
" <td>60s</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3630</th>\n", | |
" <td>920326</td>\n", | |
" <td>COVID19</td>\n", | |
" <td>MODERNA</td>\n", | |
" <td>026L20A</td>\n", | |
" <td>1</td>\n", | |
" <td>IM</td>\n", | |
" <td>LA</td>\n", | |
" <td>COVID19 (COVID19 (MODERNA))</td>\n", | |
" <td>Death</td>\n", | |
" <td>23.1</td>\n", | |
" <td>...</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>2</td>\n", | |
" <td>01/05/2021</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>Lactose</td>\n", | |
" <td>red</td>\n", | |
" <td>80s</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4121</th>\n", | |
" <td>920815</td>\n", | |
" <td>COVID19</td>\n", | |
" <td>MODERNA</td>\n", | |
" <td>NaN</td>\n", | |
" <td>1</td>\n", | |
" <td>IM</td>\n", | |
" <td>NaN</td>\n", | |
" <td>COVID19 (COVID19 (MODERNA))</td>\n", | |
" <td>Death</td>\n", | |
" <td>23.1</td>\n", | |
" <td>...</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>2</td>\n", | |
" <td>01/05/2021</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>Lisinpril, Codeine, Latex , environmental (hay fever)</td>\n", | |
" <td>red</td>\n", | |
" <td>50s</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4741</th>\n", | |
" <td>921481</td>\n", | |
" <td>COVID19</td>\n", | |
" <td>PFIZER\\BIONTECH</td>\n", | |
" <td>EL0140</td>\n", | |
" <td>1</td>\n", | |
" <td>IM</td>\n", | |
" <td>LA</td>\n", | |
" <td>COVID19 (COVID19 (PFIZER-BIONTECH))</td>\n", | |
" <td>Death</td>\n", | |
" <td>23.1</td>\n", | |
" <td>...</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>2</td>\n", | |
" <td>01/05/2021</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>NaN</td>\n", | |
" <td>No known allergies</td>\n", | |
" <td>red</td>\n", | |
" <td>80s</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table></div>" | |
], | |
"text/plain": [ | |
" VAERS_ID VAX_TYPE VAX_MANU VAX_LOT VAX_DOSE_SERIES VAX_ROUTE \\\n", | |
"1463 918065 COVID19 MODERNA 025J20-2A 1 IM \n", | |
"1759 918388 COVID19 PFIZER\\BIONTECH EL0140 1 IM \n", | |
"3630 920326 COVID19 MODERNA 026L20A 1 IM \n", | |
"4121 920815 COVID19 MODERNA NaN 1 IM \n", | |
"4741 921481 COVID19 PFIZER\\BIONTECH EL0140 1 IM \n", | |
"\n", | |
" VAX_SITE VAX_NAME SYMPTOM1 SYMPTOMVERSION1 \\\n", | |
"1463 NaN COVID19 (COVID19 (MODERNA)) Death 23.1 \n", | |
"1759 LA COVID19 (COVID19 (PFIZER-BIONTECH)) Death 23.1 \n", | |
"3630 LA COVID19 (COVID19 (MODERNA)) Death 23.1 \n", | |
"4121 NaN COVID19 (COVID19 (MODERNA)) Death 23.1 \n", | |
"4741 LA COVID19 (COVID19 (PFIZER-BIONTECH)) Death 23.1 \n", | |
"\n", | |
" ... PRIOR_VAX SPLTTYPE FORM_VERS TODAYS_DATE BIRTH_DEFECT OFC_VISIT \\\n", | |
"1463 ... NaN NaN 2 01/04/2021 NaN NaN \n", | |
"1759 ... NaN NaN 2 01/04/2021 NaN NaN \n", | |
"3630 ... NaN NaN 2 01/05/2021 NaN NaN \n", | |
"4121 ... NaN NaN 2 01/05/2021 NaN NaN \n", | |
"4741 ... NaN NaN 2 01/05/2021 NaN NaN \n", | |
"\n", | |
" ER_ED_VISIT ALLERGIES POLITICS \\\n", | |
"1463 NaN - Clozaril - Tegretol blue \n", | |
"1759 NaN NKA red \n", | |
"3630 NaN Lactose red \n", | |
"4121 NaN Lisinpril, Codeine, Latex , environmental (hay... red \n", | |
"4741 NaN No known allergies red \n", | |
"\n", | |
" AGE_DECADE \n", | |
"1463 60s \n", | |
"1759 60s \n", | |
"3630 80s \n", | |
"4121 50s \n", | |
"4741 80s \n", | |
"\n", | |
"[5 rows x 54 columns]" | |
] | |
}, | |
"execution_count": 28, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"death.head(5)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"id": "6c5d3a09-0ab5-4bef-aee8-f0cbcf2be3d7", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<iframe\n", | |
" scrolling=\"no\"\n", | |
" width=\"100%\"\n", | |
" height=\"545px\"\n", | |
" src=\"iframe_figures/figure_8.html\"\n", | |
" frameborder=\"0\"\n", | |
" allowfullscreen\n", | |
"></iframe>\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# Import plotly and create a figure\n", | |
"import plotly.graph_objects as go\n", | |
"fig = go.Figure()\n", | |
"\n", | |
"\n", | |
"# Add the histogram traces to the figure\n", | |
"for column_header in ['STATE']:\n", | |
" fig.add_trace(go.Histogram(x=death[column_header], name=str(column_header)))\n", | |
"\n", | |
"# Update the layout\n", | |
"# See Plotly documentation for customizations: https://plotly.com/python/reference/histogram/\n", | |
"fig.update_layout(\n", | |
"\txaxis_title=\"State\",\n", | |
" title=\"VAERS Reported COVID Vaccine Deaths by State (2021)\",\n", | |
" barmode='group'\n", | |
").update_xaxes(categoryorder='total descending')\n", | |
"\n", | |
"fig.show(renderer=\"iframe\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 18, | |
"id": "523c7bac-11e6-469d-b7b0-f64cf8a09e6d", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" STATE VAERS_ID count\n", | |
"18 KY 535\n", | |
"46 TX 437\n", | |
"4 CA 422\n", | |
"10 GA 330\n", | |
"9 FL 328\n", | |
"24 MN 319\n", | |
"45 TN 275\n", | |
"23 MI 259\n", | |
"36 NY 250\n", | |
"15 IL 227\n", | |
"37 OH 219\n", | |
"51 WI 190\n", | |
"50 WA 183\n", | |
"40 PA 173\n", | |
"25 MO 166\n", | |
"33 NJ 147\n", | |
"16 IN 125\n", | |
"29 NC 113\n", | |
"48 VA 102\n", | |
"20 MA 100\n", | |
"21 MD 91\n", | |
"5 CO 84\n", | |
"2 AR 84\n", | |
"3 AZ 79\n", | |
"41 PR 77\n", | |
"28 MT 74\n", | |
"13 IA 71\n", | |
"39 OR 63\n", | |
"1 AL 62\n", | |
"43 SC 61\n", | |
"19 LA 55\n", | |
"17 KS 55\n", | |
"6 CT 48\n", | |
"34 NM 47\n", | |
"27 MS 47\n", | |
"44 SD 45\n", | |
"38 OK 42\n", | |
"32 NH 41\n", | |
"52 WV 40\n", | |
"30 ND 39\n", | |
"35 NV 38\n", | |
"12 HI 36\n", | |
"0 AK 35\n", | |
"31 NE 32\n", | |
"22 ME 28\n", | |
"47 UT 25\n", | |
"8 DE 24\n", | |
"53 WY 20\n", | |
"14 ID 17\n", | |
"7 DC 13\n", | |
"42 RI 12\n", | |
"49 VT 9\n", | |
"26 MP 5\n", | |
"11 GU 3\n", | |
"54 XB 2\n" | |
] | |
} | |
], | |
"source": [ | |
"from typing import Any, Dict, List\n", | |
"def flatten_column_header(column_header: Any):\n", | |
" if isinstance(column_header, list) or isinstance(column_header, tuple):\n", | |
" column_header_str = [str(ch) for ch in column_header]\n", | |
" return ' '.join(column_header_str).strip()\n", | |
"\n", | |
" return column_header\n", | |
"\n", | |
"unused_columns = death.columns.difference(set(['STATE']).union(set([])).union(set({'VAERS_ID'})))\n", | |
"tmp_df = death.drop(unused_columns, axis=1)\n", | |
"pivot_table = tmp_df.pivot_table(\n", | |
" index=['STATE'],\n", | |
" values=['VAERS_ID'],\n", | |
" aggfunc={'VAERS_ID': ['count']}\n", | |
")\n", | |
"pivot_table.columns = [flatten_column_header(col) for col in pivot_table.columns.values]\n", | |
"death_pivot = pivot_table.reset_index()\n", | |
"\n", | |
"death_pivot = death_pivot.sort_values(by='VAERS_ID count', ascending=False, na_position='last')\n", | |
"print(death_pivot)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"id": "3701ef66-0980-486d-bacb-9488ffc4aa88", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"blue = ['AZ', 'CA', 'CO', 'CT', 'DE', 'GA', 'HI', 'IL', 'ME', 'MD', 'MA', 'MI', 'MN', 'NV', 'NH', 'NJ', 'NM', 'NY', 'OR', 'PA', 'RI', 'VT', 'VA', 'WA', 'WI']\n", | |
"red = ['AL', 'AK', 'AR', 'FL', 'ID', 'IN', 'IA', 'KS', 'KY', 'LA', 'MS', 'MO', 'MT', 'NE', 'NC', 'ND', 'OH', 'OK', 'SC', 'SD', 'TN', 'TX', 'UT', 'WV', 'WY']" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 19, | |
"id": "733e43c7-b9e8-4278-9ebc-cd88b21cfac8", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def redorblue(state):\n", | |
" if state in red:\n", | |
" return 'red'\n", | |
" elif state in blue:\n", | |
" return 'blue'\n", | |
" else:\n", | |
" return \"unknown\"\n", | |
"\n", | |
"\n", | |
"death['POLITICS'] = death['STATE'].apply(lambda x : redorblue(x))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 20, | |
"id": "a61225e3-e611-4f83-a790-9f38088bca2a", | |
"metadata": { | |
"tags": [] | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<iframe\n", | |
" scrolling=\"no\"\n", | |
" width=\"100%\"\n", | |
" height=\"545px\"\n", | |
" src=\"iframe_figures/figure_20.html\"\n", | |
" frameborder=\"0\"\n", | |
" allowfullscreen\n", | |
"></iframe>\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"import plotly.graph_objects as go\n", | |
"fig = go.Figure()\n", | |
"\n", | |
"\n", | |
"# Add the histogram traces to the figure\n", | |
"for column_header in ['POLITICS']:\n", | |
" fig.add_trace(go.Histogram(x=death[column_header], name=str(column_header)))\n", | |
"\n", | |
"# Update the layout\n", | |
"# See Plotly documentation for customizations: https://plotly.com/python/reference/histogram/\n", | |
"fig.update_layout(\n", | |
"\txaxis_title=str(0),\n", | |
" title=\"POLITICS frequencies\",\n", | |
" barmode='group'\n", | |
")\n", | |
"fig.show(renderer=\"iframe\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 21, | |
"id": "cec4a123-e71b-40b4-af5d-7cccb5b34c44", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"death['AGE_DECADE'] = pd.cut(x=death['AGE_YRS'], bins=[9, 19, 20, 29, 39, 49, 59, 69, 79, 89, 99, 109], labels=['children', 'teens', '20s', '30s', '40s', \n", | |
" '50s', '60s', '70s', '80s', '90s', '100s'])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 22, | |
"id": "36719180-a13c-49aa-85de-e03cf5a14325", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<iframe\n", | |
" scrolling=\"no\"\n", | |
" width=\"100%\"\n", | |
" height=\"545px\"\n", | |
" src=\"iframe_figures/figure_22.html\"\n", | |
" frameborder=\"0\"\n", | |
" allowfullscreen\n", | |
"></iframe>\n" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"# Import plotly and create a figure\n", | |
"import plotly.graph_objects as go\n", | |
"fig = go.Figure()\n", | |
"\n", | |
"\n", | |
"# Add the histogram traces to the figure\n", | |
"for column_header in ['AGE_DECADE']:\n", | |
" fig.add_trace(go.Histogram(x=death[column_header], name=str(column_header)))\n", | |
"\n", | |
"# Update the layout\n", | |
"# See Plotly documentation for customizations: https://plotly.com/python/reference/histogram/\n", | |
"fig.update_layout(\n", | |
"\txaxis_title='Age Group',\n", | |
" title=\"Deaths by Age from COVID Vaccines (2021)\",\n", | |
" barmode='group'\n", | |
").update_xaxes(categoryorder='total descending')\n", | |
"\n", | |
"fig.show(renderer=\"iframe\")" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 25, | |
"id": "b79367bc-c48f-4d1c-9b54-dc1491cf5ddd", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"unused_columns = death.columns.difference(set(['AGE_DECADE']).union(set([])).union(set({'VAERS_ID'})))\n", | |
"tmp_df = death.drop(unused_columns, axis=1)\n", | |
"pivot_table_age = tmp_df.pivot_table(\n", | |
" index=['AGE_DECADE'],\n", | |
" values=['VAERS_ID'],\n", | |
" aggfunc={'VAERS_ID': ['count']}\n", | |
")\n", | |
"pivot_table_age.columns = [flatten_column_header(col) for col in pivot_table_age.columns.values]\n", | |
"age_pivot = pivot_table.reset_index()\n", | |
"\n", | |
"# Sorted VAERS_ID count in death_pivot in descending order\n", | |
"age_pivot = age_pivot.sort_values(by='VAERS_ID count', ascending=False, na_position='last')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 26, | |
"id": "6d7d83ef-fd08-4bd9-b5c8-191e51acd2ee", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
" AGE_DECADE VAERS_ID count\n", | |
"8 80s 1937\n", | |
"7 70s 1930\n", | |
"6 60s 1445\n", | |
"9 90s 906\n", | |
"5 50s 623\n", | |
"4 40s 311\n", | |
"3 30s 180\n", | |
"2 20s 83\n", | |
"10 100s 57\n", | |
"0 children 34\n", | |
"1 teens 4\n" | |
] | |
} | |
], | |
"source": [ | |
"print(age_pivot)" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"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.8.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment