Commit 9dfd7f34 authored by Liwen Huang's avatar Liwen Huang
Browse files

Upload New File

parent ca0977cb
%% Cell type:markdown id: tags:
## Question 2¶
It would be interesting to see if there is any evidence of a link between vaccine effectiveness and sex of the child. Calculate the ratio of the number of children who contracted chickenpox but were vaccinated against it (at least one varicella dose) versus those who were vaccinated but did not contract chicken pox. Return results by sex.
This function should return a dictionary in the form of (use the correct numbers):
{"male":0.2,
"female":0.4}
Note: To aid in verification, the chickenpox_by_sex()['female'] value the autograder is looking for starts with the digits 0.00779.
%% Cell type:code id: tags:
``` python
import numpy as np
import pandas as pd
df = pd.read_csv('datasets/NISPUF17.csv', index_col=0)
df.head()
```
%%%% Output: execute_result
SEQNUMC SEQNUMHH PDAT PROVWT_D RDDWT_D STRATUM YEAR AGECPOXR \
1 128521 12852 2 NaN 235.916956 1031 2017 NaN
2 10741 1074 2 NaN 957.353840 1068 2017 NaN
3 220011 22001 2 NaN 189.611299 1050 2017 NaN
4 86131 8613 1 675.430817 333.447418 1040 2017 NaN
5 227141 22714 1 482.617748 278.768063 1008 2017 NaN
HAD_CPOX AGEGRP ... XVRCTY2 XVRCTY3 XVRCTY4 XVRCTY5 XVRCTY6 \
1 2 1 ... NaN NaN NaN
2 2 1 ... NaN NaN NaN
3 2 3 ... NaN NaN NaN
4 2 1 ... NaN NaN NaN
5 2 1 ... NaN NaN NaN
XVRCTY7 XVRCTY8 XVRCTY9 INS_STAT2_I INS_BREAK_I
1 NaN NaN NaN NaN NaN
2 NaN NaN NaN NaN NaN
3 NaN NaN NaN NaN NaN
4 NaN NaN NaN 1.0 2.0
5 NaN NaN NaN 2.0 1.0
[5 rows x 453 columns]
%% Cell type:code id: tags:
``` python
chc = df[['SEX','HAD_CPOX','P_NUMVRC']]
chc.head()
```
%%%% Output: execute_result
SEX HAD_CPOX P_NUMVRC
1 1 2 NaN
2 1 2 NaN
3 2 2 NaN
4 2 2 1.0
5 2 2 0.0
%% Cell type:code id: tags:
``` python
chc_had = df['HAD_CPOX'].gt(3)
chc_had.head()
```
%%%% Output: execute_result
1 False
2 False
3 False
4 False
5 False
Name: HAD_CPOX, dtype: bool
%% Cell type:code id: tags:
``` python
chc_num = df['P_NUMVRC'].gt(0)
chc_num.head
```
%%%% Output: execute_result
<bound method NDFrame.head of 1 False
2 False
3 False
4 True
5 False
...
28461 False
28462 False
28463 False
28464 False
28465 False
Name: P_NUMVRC, Length: 28465, dtype: bool>
%% Cell type:code id: tags:
``` python
chc_sex = df['HAD_CPOX'].gt(3) & df['P_NUMVRC'].gt(0)
chc_sex.head()
```
%%%% Output: execute_result
1 False
2 False
3 False
4 False
5 False
dtype: bool
%% Cell type:code id: tags:
``` python
chc_sex = df[df['HAD_CPOX'].lt(3) & df['P_NUMVRC'].gt(0)].loc[:,['HAD_CPOX','SEX']]
chc_sex.head()
```
%%%% Output: execute_result
HAD_CPOX SEX
4 2 2
7 2 2
11 2 1
13 2 1
17 2 1
%% Cell type:code id: tags:
``` python
# HAD_CPOX: 1-Y; 2-N
# SEX: 1-M; 2-F
```
%% Cell type:code id: tags:
``` python
chc_1 = len(chc_sex[(chc_sex['HAD_CPOX'] == 1) & (chc_sex['SEX'] == 1)])
chc_1
```
%%%% Output: execute_result
68
%% Cell type:code id: tags:
``` python
chc_2 = len(chc_sex[(chc_sex['HAD_CPOX'] == 1) & (chc_sex['SEX'] == 2)])
chc_2
```
%%%% Output: execute_result
53
%% Cell type:code id: tags:
``` python
chn_1 = len(chc_sex[(chc_sex['HAD_CPOX'] == 2) & (chc_sex['SEX'] == 1)])
chn_1
```
%%%% Output: execute_result
7028
%% Cell type:code id: tags:
``` python
chn_2 = len(chc_sex[(chc_sex['HAD_CPOX'] == 2) & (chc_sex['SEX'] == 2)])
chn_2
```
%%%% Output: execute_result
6802
%% Cell type:code id: tags:
``` python
ratio_chc = {'male':0,
'female':0}
ratio_chc['male'] = chc_1/chn_1
ratio_chc['female'] = chc_2/chn_2
ratio_chc
```
%%%% Output: execute_result
{'male': 0.009675583380762664, 'female': 0.0077918259335489565}
%% Cell type:code id: tags:
``` python
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment