<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> from collections import defaultdict <EOL> import numpy as np <EOL> import sys <EOL> import thinkstats2 <EOL> def ReadFemPreg ( dct_file = '<STR_LIT>' , <EOL> dat_file = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> dct = thinkstats2 . ReadStataDct ( dct_file ) <EOL> preg = dct . ReadFixedWidth ( dat_file , compression = '<STR_LIT>' ) <EOL> CleanFemPreg ( preg ) <EOL> return preg <EOL> def CleanFemPreg ( preg ) : <EOL> """<STR_LIT>""" <EOL> preg . agepreg /= <NUM_LIT> <EOL> preg . loc [ preg . birthwgt_lb > <NUM_LIT:20> , '<STR_LIT>' ] = np . nan <EOL> na_vals = [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] <EOL> preg . birthwgt_lb . replace ( na_vals , np . nan , inplace = True ) <EOL> preg . birthwgt_oz . replace ( na_vals , np . nan , inplace = True ) <EOL> preg . hpagelb . replace ( na_vals , np . nan , inplace = True ) <EOL> preg . babysex . replace ( [ <NUM_LIT:7> , <NUM_LIT:9> ] , np . nan , inplace = True ) <EOL> preg . nbrnaliv . replace ( [ <NUM_LIT:9> ] , np . nan , inplace = True ) <EOL> preg [ '<STR_LIT>' ] = preg . birthwgt_lb + preg . birthwgt_oz / <NUM_LIT> <EOL> preg . cmintvw = np . nan <EOL> def MakePregMap ( preg ) : <EOL> """<STR_LIT>""" <EOL> d = defaultdict ( list ) <EOL> for index , caseid in preg . caseid . iteritems ( ) : <EOL> d [ caseid ] . append ( index ) <EOL> return d <EOL> def main ( script ) : <EOL> """<STR_LIT>""" <EOL> preg = ReadFemPreg ( ) <EOL> print ( preg . shape ) <EOL> assert len ( preg ) == <NUM_LIT> <EOL> assert preg . caseid [ <NUM_LIT> ] == <NUM_LIT> <EOL> assert preg . pregordr . value_counts ( ) [ <NUM_LIT:1> ] == <NUM_LIT> <EOL> assert preg . nbrnaliv . value_counts ( ) [ <NUM_LIT:1> ] == <NUM_LIT> <EOL> assert preg . babysex . value_counts ( ) [ <NUM_LIT:1> ] == <NUM_LIT> <EOL> assert preg . birthwgt_lb . value_counts ( ) [ <NUM_LIT:7> ] == <NUM_LIT> <EOL> assert preg . birthwgt_oz . value_counts ( ) [ <NUM_LIT:0> ] == <NUM_LIT> <EOL> assert preg . prglngth . value_counts ( ) [ <NUM_LIT> ] == <NUM_LIT> <EOL> assert preg . outcome . value_counts ( ) [ <NUM_LIT:1> ] == <NUM_LIT> <EOL> assert preg . birthord . value_counts ( ) [ <NUM_LIT:1> ] == <NUM_LIT> <EOL> assert preg . agepreg . value_counts ( ) [ <NUM_LIT> ] == <NUM_LIT:100> <EOL> assert preg . totalwgt_lb . value_counts ( ) [ <NUM_LIT> ] == <NUM_LIT> <EOL> weights = preg . finalwgt . value_counts ( ) <EOL> key = max ( weights . keys ( ) ) <EOL> assert preg . finalwgt . value_counts ( ) [ key ] == <NUM_LIT:6> <EOL> print ( '<STR_LIT>' % script ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( * sys . argv ) </s>
