Skip to content

Instantly share code, notes, and snippets.

@fijiaaron
Last active July 12, 2019 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fijiaaron/e64e4fd260e8085e1f272a68398923c6 to your computer and use it in GitHub Desktop.
Save fijiaaron/e64e4fd260e8085e1f272a68398923c6 to your computer and use it in GitHub Desktop.
import nsfg
df = nsfg.ReadFemPreg()
def first_babies(df):
for index, row in df.iterrows():
if row.prgoutcome == 1: # only report on live births
print(index, row.caseid, row.prgoutcome, row.pregordr, row.birthord, row.wksgest)
first_babies(df)
@fijiaaron
Copy link
Author

Create the file first_babies.py in your ThinkStats2/code directory.
Run it from the terminal with the command python first_babies.py
It currently prints information for all babies born alive.

Assignment: Make it print only the first born babies.
Bonus: return the total number of first born babies

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment