Format: text/x-python
⬇ Download File (636 B)
   1  # -*- coding: utf-8 -*-
   2  """
   3  Created on Sat May 22 23:52:57 2021
   4  
   5  @author: PC
   6  """
   7  
   8  import pandas as pd
   9  import os
  10  
  11  os.chdir(r'C:\Users\PC\Pytho')
  12  
  13  df= pd.read_csv('NISPUF17.csv')
  14  df= df[['SEX', 'HAD_CPOX', 'P_NUMVRC']]
  15  df= df[df['P_NUMVRC'] > 0]  #Vacinated atleast once
  16  
  17  #(male, had_cpox) / (male, not_had_cpox)
  18  #(female, had_cpox) / (female, not_had_cpox)
  19  result = { 'male':  len(df[ (df['SEX']==1) &  (df['HAD_CPOX']==1)])/len(df[ (df['SEX']==1) &  (df['HAD_CPOX']==2)]),
  20            'female': len( df[ (df['SEX']==2)  & (df['HAD_CPOX']==1) ])/ len( df[ (df['SEX']==2)  & (df['HAD_CPOX']==2) ])
  21      }
  22  
  23  print(result)