Module Expr Str ImportFrom alias ImportFrom alias Import alias identifier Import alias Import alias FunctionDef arguments args NameParam NameParam defaults Str Str body Expr Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad keyword Str Expr Call NameLoad NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str AugAssignDiv AttributeStore NameLoad attr Num Assign SubscriptStore AttributeLoad NameLoad attr Index TupleLoad CompareGt AttributeLoad NameLoad attr Num Str AttributeLoad NameLoad attr Assign NameStore ListLoad Num Num Num Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad AttributeLoad NameLoad attr keyword NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad AttributeLoad NameLoad attr keyword NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad AttributeLoad NameLoad attr keyword NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr ListLoad Num Num AttributeLoad NameLoad attr keyword NameLoad Expr Call AttributeLoad AttributeLoad NameLoad attr attr ListLoad Num AttributeLoad NameLoad attr keyword NameLoad Assign SubscriptStore NameLoad Index Str BinOpAdd AttributeLoad NameLoad attr BinOpDiv AttributeLoad NameLoad attr Num Assign AttributeStore NameLoad attr AttributeLoad NameLoad attr decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call NameLoad NameLoad For TupleStore NameStore NameStore Call AttributeLoad AttributeLoad NameLoad attr attr body Expr Call AttributeLoad SubscriptLoad NameLoad Index NameLoad attr NameLoad Return NameLoad decorator_list FunctionDef arguments args NameParam defaults body Expr Str Assign NameStore Call NameLoad Expr Call NameLoad AttributeLoad NameLoad attr Assert CompareEq Call NameLoad NameLoad Num Assert CompareEq SubscriptLoad AttributeLoad NameLoad attr Index Num Num Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index Num Num Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index Num Num Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index Num Num Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index Num Num Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index Num Num Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index Num Num Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index Num Num Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index Num Num Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index Num Num Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index Num Num Assign NameStore Call AttributeLoad AttributeLoad NameLoad attr attr Assign NameStore Call NameLoad Call AttributeLoad NameLoad attr Assert CompareEq SubscriptLoad Call AttributeLoad AttributeLoad NameLoad attr attr Index NameLoad Num Expr Call NameLoad BinOpMod Str NameLoad decorator_list If CompareEq NameLoad Str body Expr Call NameLoad AttributeLoad NameLoad attr
N/A N/A This file contains code for use with "Think Stats",
by Allen B. Downey, available from greenteapress.com

Copyright 2010 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
 __future__ print_function collections defaultdict N/A numpy np N/A sys N/A thinkstats2 ReadFemPreg N/A N/A dct_file dat_file N/A 2002FemPreg.dct 2002FemPreg.dat.gz N/A N/A Reads the NSFG pregnancy data.

    dct_file: string file name
    dat_file: string file name

    returns: DataFrame
     N/A dct N/A N/A thinkstats2 ReadStataDct dct_file N/A preg N/A N/A dct ReadFixedWidth dat_file compression gzip N/A N/A CleanFemPreg preg N/A preg N/A CleanFemPreg N/A N/A preg N/A N/A N/A Recodes variables from the pregnancy frame.

    preg: DataFrame
     N/A N/A preg agepreg 100.0 N/A N/A N/A preg loc N/A N/A N/A N/A preg birthwgt_lb 20 birthwgt_lb N/A np nan N/A na_vals N/A 97 98 99 N/A N/A N/A N/A preg birthwgt_lb replace na_vals N/A np nan inplace True N/A N/A N/A N/A preg birthwgt_oz replace na_vals N/A np nan inplace True N/A N/A N/A N/A preg hpagelb replace na_vals N/A np nan inplace True N/A N/A N/A N/A preg babysex replace N/A 7 9 N/A np nan inplace True N/A N/A N/A N/A preg nbrnaliv replace N/A 9 N/A np nan inplace True N/A N/A preg N/A totalwgt_lb N/A N/A preg birthwgt_lb N/A N/A preg birthwgt_oz 16.0 N/A N/A preg cmintvw N/A np nan N/A MakePregMap N/A N/A preg N/A N/A N/A Make a map from caseid to list of preg indices.

    preg: DataFrame

    returns: dict that maps from caseid to list of indices into preg df
     N/A d N/A defaultdict list N/A N/A index caseid N/A N/A N/A preg caseid iteritems N/A N/A N/A N/A N/A d N/A caseid append index N/A d N/A main N/A N/A script N/A N/A N/A Tests the functions in this module.

    script: string script name
     N/A preg N/A ReadFemPreg N/A N/A print N/A preg shape N/A N/A N/A len preg 13593 N/A N/A N/A N/A preg caseid N/A 13592 12571 N/A N/A N/A N/A N/A N/A preg pregordr value_counts N/A 1 5033 N/A N/A N/A N/A N/A N/A preg nbrnaliv value_counts N/A 1 8981 N/A N/A N/A N/A N/A N/A preg babysex value_counts N/A 1 4641 N/A N/A N/A N/A N/A N/A preg birthwgt_lb value_counts N/A 7 3049 N/A N/A N/A N/A N/A N/A preg birthwgt_oz value_counts N/A 0 1037 N/A N/A N/A N/A N/A N/A preg prglngth value_counts N/A 39 4744 N/A N/A N/A N/A N/A N/A preg outcome value_counts N/A 1 9148 N/A N/A N/A N/A N/A N/A preg birthord value_counts N/A 1 4413 N/A N/A N/A N/A N/A N/A preg agepreg value_counts N/A 22.75 100 N/A N/A N/A N/A N/A N/A preg totalwgt_lb value_counts N/A 7.5 302 N/A weights N/A N/A N/A preg finalwgt value_counts N/A key N/A max N/A N/A weights keys N/A N/A N/A N/A N/A N/A preg finalwgt value_counts N/A key 6 N/A N/A print N/A %s: All tests passed. script N/A N/A N/A __name__ __main__ N/A N/A N/A main N/A sys argv